Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .cdsrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"requires": {
"db": {
"model": [
"@cap-js/beershop"
],
"kind": "cosmos"
},
"kinds": {
"cosmos": {
"impl": "@cap-js/cosmos-db-plugin"
}
}
}
}
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye
20 changes: 20 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "Node.js & TypeScript",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
// "image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye",
"dockerComposeFile": "docker-compose.yml",
"service": "devcontainer",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}"
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
17 changes: 17 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'
services:
devcontainer:
build:
context: .
dockerfile: Dockerfile
volumes:
- ../..:/workspaces:cached
network_mode: service:db
command: sleep infinity

db:
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
# restart: unless-stopped
environment:
AZURE_COSMOS_EMULATOR_PARTITION_COUNT: 10
AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE: true
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
};
29 changes: 29 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: CI

on:
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
# - run: npm run build --if-present
- run: npm test --workspace=cosmos-db
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ dist

# for now to KISS
package-lock.json
*.sqlite
*.sqlite
.cdsrc-private.json
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"esbenp.prettier-vscode"
],
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ to
- [Container Management]( https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/cosmosdb/cosmos/samples/v3/javascript/ContainerManagement.js)
- [AAD auth - only if you don't want to use master keys](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/cosmosdb/cosmos/samples/v3/javascript/AADAuth.js)

```
# Cosmos UI for the hackathon databases
Open cosmos.azure.com (make sure that you are not signed in - there should be a "Signin" button and a link allowing to login via connection string

Use this connection string `AccountEndpoint=https://hackathon-recap.documents.azure.com:443/;AccountKey=90NT3CKZPVTGsP3yaa1Khb2ur5rJCUwWZku0MxCK7eC8DQTTzugAmNnsqAHR0QZsDkEgRKBmg2v0ACDbKpvJoQ==;`
17 changes: 0 additions & 17 deletions cosmos-db/etc/cosmos-stack.yml

This file was deleted.

63 changes: 0 additions & 63 deletions cosmos-db/lib/CosmosService.js

This file was deleted.

31 changes: 0 additions & 31 deletions cosmos-db/package.json

This file was deleted.

25 changes: 0 additions & 25 deletions cosmos-db/test/crud.test.js

This file was deleted.

92 changes: 43 additions & 49 deletions min-sample/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ts-check
const CosmosClient = require('@azure/cosmos').CosmosClient

const config = require('./config')
Expand All @@ -12,10 +11,10 @@ const containerId = config.container.id
const partitionKey = { kind: 'Hash', paths: ['/partitionKey'] }

const options = {
endpoint: endpoint,
key: key,
userAgentSuffix: 'CosmosDBJavascriptQuickstart'
};
endpoint: endpoint,
key: key,
userAgentSuffix: 'CosmosDBJavascriptQuickstart'
};

const client = new CosmosClient(options)

Expand Down Expand Up @@ -71,35 +70,30 @@ async function scaleContainer() {
.database(databaseId)
.container(containerId)
.read();

try
{
const {resources: offers} = await client.offers.readAll().fetchAll();

const newRups = 500;
for (var offer of offers) {
if (containerDefinition._rid !== offer.offerResourceId)
{
continue;
}
offer.content.offerThroughput = newRups;
const offerToReplace = client.offer(offer.id);
await offerToReplace.replace(offer);
console.log(`Updated offer to ${newRups} RU/s\n`);
break;

try {
const { resources: offers } = await client.offers.readAll().fetchAll();

const newRups = 500;
for (var offer of offers) {
if (containerDefinition._rid !== offer.offerResourceId) {
continue;
}
offer.content.offerThroughput = newRups;
const offerToReplace = client.offer(offer.id);
await offerToReplace.replace(offer);
console.log(`Updated offer to ${newRups} RU/s\n`);
break;
}
}
catch(err)
{
if (err.code == 400)
{
console.log(`Cannot read container throuthput.\n`);
console.log(err.body.message);
}
else
{
throw err;
}
catch (err) {
if (err.code == 400) {
console.log(`Cannot read container throuthput.\n`);
console.log(err.body.message);
}
else {
throw err;
}
}
}

Expand Down Expand Up @@ -188,20 +182,20 @@ function exit(message) {
process.stdin.on('data', process.exit.bind(process, 0))
}

// createDatabase()
// .then(() => readDatabase())
// .then(() => createContainer())
// .then(() => readContainer())
// .then(() => scaleContainer())
// .then(() => createFamilyItem(config.items.Andersen))
// .then(() => createFamilyItem(config.items.Wakefield))
// .then(() => queryContainer())
// .then(() => replaceFamilyItem(config.items.Andersen))
// .then(() => queryContainer())
// .then(() => deleteFamilyItem(config.items.Andersen))
// .then(() => {
// exit(`Completed successfully`)
// })
// .catch(error => {
// exit(`Completed with error ${JSON.stringify(error)}`)
// })
createDatabase()
.then(() => readDatabase())
.then(() => createContainer())
.then(() => readContainer())
.then(() => scaleContainer())
.then(() => createFamilyItem(config.items.Andersen))
.then(() => createFamilyItem(config.items.Wakefield))
.then(() => queryContainer())
.then(() => replaceFamilyItem(config.items.Andersen))
.then(() => queryContainer())
.then(() => deleteFamilyItem(config.items.Andersen))
.then(() => {
exit(`Completed successfully`)
})
.catch(error => {
exit(`Completed with error ${JSON.stringify(error)}`)
})
Loading