@nitwel/sandbox 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.d.ts CHANGED
@@ -279,5 +279,6 @@ export type Env = (typeof baseConfig)[Database] & {
279
279
  CACHE_ENABLED: string;
280
280
  PUBLIC_URL: string;
281
281
  NODE_ENV: string;
282
+ DOCKER_DEFAULT_PLATFORM?: string;
282
283
  } & Partial<typeof minio> & Partial<typeof saml> & Partial<typeof maildev>;
283
284
  export {};
package/dist/config.js CHANGED
@@ -146,6 +146,7 @@ export async function getEnv(database, opts) {
146
146
  REDIS_ENABLED: String(opts.extras.redis),
147
147
  CACHE_ENABLED: String(opts.cache),
148
148
  NODE_ENV: opts.dev ? 'development' : 'production',
149
+ ...(process.arch === 'arm64' ? { DOCKER_DEFAULT_PLATFORM: 'linux/amd64' } : {}),
149
150
  ...(opts.extras.minio ? minio : {}),
150
151
  ...(opts.extras.saml ? saml : {}),
151
152
  ...(opts.extras.maildev ? maildev : {}),
@@ -1,14 +1,14 @@
1
- services:
2
- cockroachdb:
3
- # change in the YY.R component denotes a major release
4
- image: cockroachdb/cockroach:${DB_VERSION}
5
- tmpfs: /cockroach/cockroach-data
6
- command: start-single-node --cluster-name=example-single-node --insecure
7
- ports:
8
- - ${DB_PORT}:26257
9
- - ${COCKROACH_UI}:8080
10
- healthcheck:
11
- test: ['CMD', 'curl', '--fail', 'http://localhost:8080/health']
12
- interval: 5s
13
- timeout: 5s
14
- retries: 10
1
+ services:
2
+ cockroachdb:
3
+ # change in the YY.R component denotes a major release
4
+ image: cockroachdb/cockroach:${DB_VERSION}
5
+ tmpfs: /cockroach/cockroach-data
6
+ command: start-single-node --cluster-name=example-single-node --insecure
7
+ ports:
8
+ - ${DB_PORT}:26257
9
+ - ${COCKROACH_UI}:8080
10
+ healthcheck:
11
+ test: ['CMD', 'curl', '--fail', 'http://localhost:8080/health']
12
+ interval: 5s
13
+ timeout: 5s
14
+ retries: 10
@@ -1,12 +1,12 @@
1
- services:
2
- maildev:
3
- image: maildev/maildev:latest
4
- ports:
5
- - '${MAILDEV_WEBUI}:1080' # Web interface
6
- - '${EMAIL_SMTP_PORT}:1025' # SMTP server
7
- restart: always
8
- environment:
9
- - MAILDEV_WEB_PORT=1080
10
- - MAILDEV_SMTP_PORT=1025
11
- - MAILDEV_INCOMING_USER=${EMAIL_SMTP_USER}
12
- - MAILDEV_INCOMING_PASS=${EMAIL_SMTP_PASSWORD}
1
+ services:
2
+ maildev:
3
+ image: maildev/maildev:latest
4
+ ports:
5
+ - '${MAILDEV_WEBUI}:1080' # Web interface
6
+ - '${EMAIL_SMTP_PORT}:1025' # SMTP server
7
+ restart: always
8
+ environment:
9
+ - MAILDEV_WEB_PORT=1080
10
+ - MAILDEV_SMTP_PORT=1025
11
+ - MAILDEV_INCOMING_USER=${EMAIL_SMTP_USER}
12
+ - MAILDEV_INCOMING_PASS=${EMAIL_SMTP_PASSWORD}
@@ -1,16 +1,16 @@
1
- services:
2
- maria:
3
- image: mariadb:${DB_VERSION}
4
- tmpfs: /var/lib/mysql
5
- command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
6
- environment:
7
- MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
8
- MYSQL_USER: ${DB_USER}
9
- MYSQL_DATABASE: ${DB_DATABASE}
10
- ports:
11
- - ${DB_PORT}:3306
12
- healthcheck:
13
- test: ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized']
14
- interval: 5s
15
- timeout: 5s
16
- retries: 10
1
+ services:
2
+ maria:
3
+ image: mariadb:${DB_VERSION}
4
+ tmpfs: /var/lib/mysql
5
+ command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
6
+ environment:
7
+ MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
8
+ MYSQL_USER: ${DB_USER}
9
+ MYSQL_DATABASE: ${DB_DATABASE}
10
+ ports:
11
+ - ${DB_PORT}:3306
12
+ healthcheck:
13
+ test: ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized']
14
+ interval: 5s
15
+ timeout: 5s
16
+ retries: 10
@@ -1,24 +1,24 @@
1
- services:
2
- minio:
3
- # should stay compatible via S3 driver
4
- image: minio/minio
5
- command: server /data/minio/ --console-address :9001
6
- ports:
7
- - ${MINIO_PORT}:9000
8
- - 8882:9001
9
- environment:
10
- MINIO_ROOT_USER: directus
11
- MINIO_ROOT_PASSWORD: miniosecret
12
-
13
- minio-mc:
14
- image: minio/mc
15
- depends_on:
16
- - minio
17
- entrypoint: >
18
- /bin/sh -c " until (/usr/bin/mc alias set directusminio http://minio:9000 directus miniosecret &&
19
- /usr/bin/mc admin info directusminio > /dev/null 2>&1); do
20
- echo 'Waiting for MinIO to be ready...';
21
- sleep 1;
22
- done; /usr/bin/mc mb directusminio/directus-blackbox-test; while true; do
23
- sleep 3600;
24
- done;"
1
+ services:
2
+ minio:
3
+ # should stay compatible via S3 driver
4
+ image: minio/minio
5
+ command: server /data/minio/ --console-address :9001
6
+ ports:
7
+ - ${MINIO_PORT}:9000
8
+ - 8882:9001
9
+ environment:
10
+ MINIO_ROOT_USER: directus
11
+ MINIO_ROOT_PASSWORD: miniosecret
12
+
13
+ minio-mc:
14
+ image: minio/mc
15
+ depends_on:
16
+ - minio
17
+ entrypoint: >
18
+ /bin/sh -c " until (/usr/bin/mc alias set directusminio http://minio:9000 directus miniosecret &&
19
+ /usr/bin/mc admin info directusminio > /dev/null 2>&1); do
20
+ echo 'Waiting for MinIO to be ready...';
21
+ sleep 1;
22
+ done; /usr/bin/mc mb directusminio/directus-blackbox-test; while true; do
23
+ sleep 3600;
24
+ done;"
@@ -1,28 +1,28 @@
1
- services:
2
- mssql:
3
- image: mcr.microsoft.com/mssql/server:${DB_VERSION}
4
- tmpfs: /var/opt/mssql/data
5
- environment:
6
- - ACCEPT_EULA=Y
7
- - MSSQL_SA_PASSWORD=${DB_PASSWORD}
8
- - MSSQL_PID=Express
9
- ports:
10
- - ${DB_PORT}:1433
11
- healthcheck:
12
- test:
13
- [
14
- 'CMD',
15
- '/opt/mssql-tools18/bin/sqlcmd',
16
- '-S',
17
- 'localhost',
18
- '-U',
19
- 'sa',
20
- '-P',
21
- '${DB_PASSWORD}',
22
- '-Q',
23
- 'SELECT 1',
24
- '-No',
25
- ]
26
- interval: 5s
27
- timeout: 5s
28
- retries: 10
1
+ services:
2
+ mssql:
3
+ image: mcr.microsoft.com/mssql/server:${DB_VERSION}
4
+ tmpfs: /var/opt/mssql/data
5
+ environment:
6
+ - ACCEPT_EULA=Y
7
+ - MSSQL_SA_PASSWORD=${DB_PASSWORD}
8
+ - MSSQL_PID=Express
9
+ ports:
10
+ - ${DB_PORT}:1433
11
+ healthcheck:
12
+ test:
13
+ [
14
+ 'CMD',
15
+ '/opt/mssql-tools18/bin/sqlcmd',
16
+ '-S',
17
+ 'localhost',
18
+ '-U',
19
+ 'sa',
20
+ '-P',
21
+ '${DB_PASSWORD}',
22
+ '-Q',
23
+ 'SELECT 1',
24
+ '-No',
25
+ ]
26
+ interval: 5s
27
+ timeout: 5s
28
+ retries: 10
@@ -1,15 +1,15 @@
1
- services:
2
- mysql:
3
- image: mysql:${DB_VERSION}
4
- tmpfs: /var/lib/mysql
5
- command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
6
- environment:
7
- MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
8
- MYSQL_DATABASE: ${DB_DATABASE}
9
- ports:
10
- - ${DB_PORT}:3306
11
- healthcheck:
12
- test: ['CMD', 'mysql', '--user=root', '--password=${DB_PASSWORD}', '--execute=SELECT 1;']
13
- interval: 5s
14
- timeout: 5s
15
- retries: 10
1
+ services:
2
+ mysql:
3
+ image: mysql:${DB_VERSION}
4
+ tmpfs: /var/lib/mysql
5
+ command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
6
+ environment:
7
+ MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
8
+ MYSQL_DATABASE: ${DB_DATABASE}
9
+ ports:
10
+ - ${DB_PORT}:3306
11
+ healthcheck:
12
+ test: ['CMD', 'mysql', '--user=root', '--password=${DB_PASSWORD}', '--execute=SELECT 1;']
13
+ interval: 5s
14
+ timeout: 5s
15
+ retries: 10
@@ -1,16 +1,16 @@
1
- services:
2
- oracle:
3
- image: gvenzl/oracle-xe:${DB_VERSION}
4
- ports:
5
- - ${DB_PORT}:1521
6
- environment:
7
- - OPATCH_JRE_MEMORY_OPTIONS=-Xms128m -Xmx256m -XX:PermSize=16m -XX:MaxPermSize=32m -Xss1m
8
- - ORACLE_ALLOW_REMOTE=true
9
- - ORACLE_RANDOM_PASSWORD=yes
10
- - APP_USER=${DB_USER}
11
- - APP_USER_PASSWORD=${DB_PASSWORD}
12
- healthcheck:
13
- test: healthcheck.sh
14
- interval: 5s
15
- timeout: 5s
16
- retries: 10
1
+ services:
2
+ oracle:
3
+ image: gvenzl/oracle-xe:${DB_VERSION}
4
+ ports:
5
+ - ${DB_PORT}:1521
6
+ environment:
7
+ - OPATCH_JRE_MEMORY_OPTIONS=-Xms128m -Xmx256m -XX:PermSize=16m -XX:MaxPermSize=32m -Xss1m
8
+ - ORACLE_ALLOW_REMOTE=true
9
+ - ORACLE_RANDOM_PASSWORD=yes
10
+ - APP_USER=${DB_USER}
11
+ - APP_USER_PASSWORD=${DB_PASSWORD}
12
+ healthcheck:
13
+ test: healthcheck.sh
14
+ interval: 5s
15
+ timeout: 5s
16
+ retries: 10
@@ -1,14 +1,14 @@
1
- services:
2
- postgres:
3
- image: postgis/postgis:${DB_VERSION}
4
- environment:
5
- POSTGRES_PASSWORD: ${DB_PASSWORD}
6
- POSTGRES_USER: ${DB_USER}
7
- POSTGRES_DB: ${DB_DATABASE}
8
- ports:
9
- - ${DB_PORT}:5432
10
- healthcheck:
11
- test: ['CMD-SHELL', 'pg_isready -U ${DB_USER} -d ${DB_DATABASE}']
12
- interval: 5s
13
- timeout: 5s
14
- retries: 10
1
+ services:
2
+ postgres:
3
+ image: postgis/postgis:${DB_VERSION}
4
+ environment:
5
+ POSTGRES_PASSWORD: ${DB_PASSWORD}
6
+ POSTGRES_USER: ${DB_USER}
7
+ POSTGRES_DB: ${DB_DATABASE}
8
+ ports:
9
+ - ${DB_PORT}:5432
10
+ healthcheck:
11
+ test: ['CMD-SHELL', 'pg_isready -U ${DB_USER} -d ${DB_DATABASE}']
12
+ interval: 5s
13
+ timeout: 5s
14
+ retries: 10
@@ -1,5 +1,5 @@
1
- services:
2
- redis:
3
- image: redis:6-alpine
4
- ports:
5
- - ${REDIS_PORT}:6379
1
+ services:
2
+ redis:
3
+ image: redis:6-alpine
4
+ ports:
5
+ - ${REDIS_PORT}:6379
@@ -1,10 +1,10 @@
1
- services:
2
- saml:
3
- image: kristophjunge/test-saml-idp
4
- ports:
5
- - ${SAML_PORT}:8080
6
- environment:
7
- - SIMPLESAMLPHP_SP_ENTITY_ID=saml-test
8
- - SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE=http://127.0.0.1:8080/auth/login/saml/acs
9
- extra_hosts:
10
- - 'host.docker.internal:host-gateway'
1
+ services:
2
+ saml:
3
+ image: kristophjunge/test-saml-idp
4
+ ports:
5
+ - ${SAML_PORT}:8080
6
+ environment:
7
+ - SIMPLESAMLPHP_SP_ENTITY_ID=saml-test
8
+ - SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE=http://127.0.0.1:8080/auth/login/saml/acs
9
+ extra_hosts:
10
+ - 'host.docker.internal:host-gateway'
@@ -28,7 +28,7 @@ export async function saveSchema(env) {
28
28
  const data = await fetch(`${env.PUBLIC_URL}/schema/snapshot?access_token=${env.ADMIN_TOKEN}`);
29
29
  const snapshot = (await data.json());
30
30
  const collections = snapshot.data.collections.filter((collection) => collection.schema);
31
- const schema = `export type Schema = {
31
+ const schema = `export type Schema = {
32
32
  ${collections
33
33
  .map((collection) => {
34
34
  const collectionName = formatCollection(collection.collection);
@@ -36,13 +36,13 @@ export async function saveSchema(env) {
36
36
  return `${formatField(collection.collection)}: ${collectionName}`;
37
37
  return `${formatField(collection.collection)}: ${collectionName}[];`;
38
38
  })
39
- .join('\n ')}
40
- };
39
+ .join('\n ')}
40
+ };
41
41
  `;
42
42
  const collectionTypes = collections
43
43
  .map((collection) => {
44
44
  const collectionName = formatCollection(collection.collection);
45
- return `export type ${collectionName} = {
45
+ return `export type ${collectionName} = {
46
46
  ${snapshot.data.fields
47
47
  .filter((field) => field.collection === collection.collection)
48
48
  .map((field) => {
@@ -62,7 +62,7 @@ export async function saveSchema(env) {
62
62
  return `${fieldName} string | number | ${relation.meta.one_allowed_collections.map(formatCollection).join(' | ')};`;
63
63
  }
64
64
  })
65
- .join('\n ')}
65
+ .join('\n ')}
66
66
  };`;
67
67
  })
68
68
  .join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitwel/sandbox",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Toolkit for spinning up directus test environments",
5
5
  "homepage": "https://directus.io",
6
6
  "exports": {
@@ -36,7 +36,7 @@
36
36
  "typedoc": "0.28.12",
37
37
  "typedoc-plugin-markdown": "4.8.1",
38
38
  "typescript": "5.9.3",
39
- "@directus/types": "14.0.0"
39
+ "@directus/types": "14.3.0"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=12.20.0"
package/readme.md CHANGED
@@ -1,70 +1,70 @@
1
- # Directus Api Sandbox 🛠️
2
-
3
- Utility functions for quickly spinning up and down instances of directus for usage such as testing or development.
4
-
5
- ## Usage
6
-
7
- The package offers two ways of interacting, either through calling JS functions or through accessing the command line
8
- interface.
9
-
10
- ### CLI
11
-
12
- ```
13
- Usage: sandbox [options] <database>
14
-
15
- Arguments:
16
- database What database to start the api with (choices: "maria", "cockroachdb", "mssql", "mysql", "oracle", "postgres", "sqlite")
17
-
18
- Options:
19
- -b, --build Rebuild directus from source
20
- -d, --dev Start directus in developer mode. Not compatible with build
21
- -w, --watch Restart the api when changes are made
22
- --inspect Start the api with debugger (default: true)
23
- -p, --port <port> Port to start the api on
24
- -x, --export Export the schema to a file every 2 seconds
25
- -s, --schema [schema] Load an additional schema snapshot on startup
26
- --docker.basePort <dockerBasePort> Minimum port number to use for docker containers
27
- --docker.keep Keep containers running when stopping the sandbox
28
- --docker.name Overwrite the name of the docker project
29
- -e, --extras <extras> Enable redis,maildev,saml or other extras
30
- -i, --instances <instances> Horizontally scale directus to a given number of instances (default: "1")
31
- --killPorts Forcefully kills all processes that occupy ports that the api would use
32
- -h, --help display help for command
33
- ```
34
-
35
- ### API
36
-
37
- The api is accessed through the following two functions:
38
-
39
- - [sandbox](docs/functions/sandbox.md)
40
- - [sandboxes](docs/functions/sandboxes.md)
41
-
42
- #### Example
43
-
44
- ```ts
45
- import { sandbox } from '@directus/sandbox';
46
-
47
- const sb = await sandbox('postgres', { dev: true });
48
-
49
- // Interact via Rest, GQL or WebSockets
50
- const result = await fetch(sb.env.PUBLIC_URL + '/items/articles');
51
-
52
- console.log(await result.json());
53
-
54
- await sb.close();
55
- ```
56
-
57
- ## Inner workings
58
-
59
- Depending on what is set in the configuration, some of these steps might be skipped:
60
-
61
- 1. **Building of the api**: If enabled, the api is freshly build each time the sandbox is started. Use the `watch`
62
- option to quickly iterate on changes.
63
- 2. **Starting of the docker containers**: All required docker containers like databases or extras like redis are spun up
64
- and awaited until healthy. If the docker containers are still running, they will be reused instead of starting up new
65
- ones.
66
- 3. **Bootstrapping of the database**: If not already bootstrapped, the sandbox will make sure that all necessary
67
- database tables are created.
68
- 4. **Loading of a schema snapshot**: In case the `schema` option is set, the database will also the snapshot applied
69
- before starting directus.
70
- 5. **Starting of the api**: Finally, the api(s) are spun up with the right environment variables configured.
1
+ # Directus Api Sandbox 🛠️
2
+
3
+ Utility functions for quickly spinning up and down instances of directus for usage such as testing or development.
4
+
5
+ ## Usage
6
+
7
+ The package offers two ways of interacting, either through calling JS functions or through accessing the command line
8
+ interface.
9
+
10
+ ### CLI
11
+
12
+ ```
13
+ Usage: sandbox [options] <database>
14
+
15
+ Arguments:
16
+ database What database to start the api with (choices: "maria", "cockroachdb", "mssql", "mysql", "oracle", "postgres", "sqlite")
17
+
18
+ Options:
19
+ -b, --build Rebuild directus from source
20
+ -d, --dev Start directus in developer mode. Not compatible with build
21
+ -w, --watch Restart the api when changes are made
22
+ --inspect Start the api with debugger (default: true)
23
+ -p, --port <port> Port to start the api on
24
+ -x, --export Export the schema to a file every 2 seconds
25
+ -s, --schema [schema] Load an additional schema snapshot on startup
26
+ --docker.basePort <dockerBasePort> Minimum port number to use for docker containers
27
+ --docker.keep Keep containers running when stopping the sandbox
28
+ --docker.name Overwrite the name of the docker project
29
+ -e, --extras <extras> Enable redis,maildev,saml or other extras
30
+ -i, --instances <instances> Horizontally scale directus to a given number of instances (default: "1")
31
+ --killPorts Forcefully kills all processes that occupy ports that the api would use
32
+ -h, --help display help for command
33
+ ```
34
+
35
+ ### API
36
+
37
+ The api is accessed through the following two functions:
38
+
39
+ - [sandbox](docs/functions/sandbox.md)
40
+ - [sandboxes](docs/functions/sandboxes.md)
41
+
42
+ #### Example
43
+
44
+ ```ts
45
+ import { sandbox } from '@directus/sandbox';
46
+
47
+ const sb = await sandbox('postgres', { dev: true });
48
+
49
+ // Interact via Rest, GQL or WebSockets
50
+ const result = await fetch(sb.env.PUBLIC_URL + '/items/articles');
51
+
52
+ console.log(await result.json());
53
+
54
+ await sb.close();
55
+ ```
56
+
57
+ ## Inner workings
58
+
59
+ Depending on what is set in the configuration, some of these steps might be skipped:
60
+
61
+ 1. **Building of the api**: If enabled, the api is freshly build each time the sandbox is started. Use the `watch`
62
+ option to quickly iterate on changes.
63
+ 2. **Starting of the docker containers**: All required docker containers like databases or extras like redis are spun up
64
+ and awaited until healthy. If the docker containers are still running, they will be reused instead of starting up new
65
+ ones.
66
+ 3. **Bootstrapping of the database**: If not already bootstrapped, the sandbox will make sure that all necessary
67
+ database tables are created.
68
+ 4. **Loading of a schema snapshot**: In case the `schema` option is set, the database will also the snapshot applied
69
+ before starting directus.
70
+ 5. **Starting of the api**: Finally, the api(s) are spun up with the right environment variables configured.