@sidekickdb/platform 0.0.0 → 2.0.1
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/.tshy/build.json +8 -0
- package/.tshy/commonjs.json +16 -0
- package/.tshy/esm.json +15 -0
- package/.turbo/turbo-build.log +50 -0
- package/LICENSE.md +202 -0
- package/NOTICE +27 -0
- package/README.md +444 -2
- package/__tests__/src/apiURI.test.ts +58 -0
- package/__tests__/src/backupDownload.test.ts +427 -0
- package/__tests__/src/backups.test.ts +168 -0
- package/__tests__/src/clerk.test.ts +13 -0
- package/__tests__/src/consts.test.ts +11 -0
- package/__tests__/src/migrations.test.ts +885 -0
- package/__tests__/src/perms.test.ts +102 -0
- package/__tests__/src/rename.test.ts +126 -0
- package/__tests__/src/schema.push.e2e.test.ts +186 -0
- package/__tests__/src/schema.test.ts +644 -0
- package/__tests__/src/typescript-schema.test.ts +117 -0
- package/dist/commonjs/ProgressPromise.d.ts +18 -0
- package/dist/commonjs/ProgressPromise.d.ts.map +1 -0
- package/dist/commonjs/ProgressPromise.js +77 -0
- package/dist/commonjs/ProgressPromise.js.map +1 -0
- package/dist/commonjs/api.d.ts +480 -0
- package/dist/commonjs/api.d.ts.map +1 -0
- package/dist/commonjs/api.js +1132 -0
- package/dist/commonjs/api.js.map +1 -0
- package/dist/commonjs/backupDownload.d.ts +89 -0
- package/dist/commonjs/backupDownload.d.ts.map +1 -0
- package/dist/commonjs/backupDownload.js +357 -0
- package/dist/commonjs/backupDownload.js.map +1 -0
- package/dist/commonjs/backups.d.ts +146 -0
- package/dist/commonjs/backups.d.ts.map +1 -0
- package/dist/commonjs/backups.js +248 -0
- package/dist/commonjs/backups.js.map +1 -0
- package/dist/commonjs/clerk.d.ts +2 -0
- package/dist/commonjs/clerk.d.ts.map +1 -0
- package/dist/commonjs/clerk.js +29 -0
- package/dist/commonjs/clerk.js.map +1 -0
- package/dist/commonjs/consts.d.ts +11 -0
- package/dist/commonjs/consts.d.ts.map +1 -0
- package/dist/commonjs/consts.js +17 -0
- package/dist/commonjs/consts.js.map +1 -0
- package/dist/commonjs/crypto.d.ts +4 -0
- package/dist/commonjs/crypto.d.ts.map +1 -0
- package/dist/commonjs/crypto.js +26 -0
- package/dist/commonjs/crypto.js.map +1 -0
- package/dist/commonjs/index.d.ts +18 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +61 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/migrationUtils.d.ts +4 -0
- package/dist/commonjs/migrationUtils.d.ts.map +1 -0
- package/dist/commonjs/migrationUtils.js +52 -0
- package/dist/commonjs/migrationUtils.js.map +1 -0
- package/dist/commonjs/migrations.d.ts +99 -0
- package/dist/commonjs/migrations.d.ts.map +1 -0
- package/dist/commonjs/migrations.js +597 -0
- package/dist/commonjs/migrations.js.map +1 -0
- package/dist/commonjs/oauth.d.ts +98 -0
- package/dist/commonjs/oauth.d.ts.map +1 -0
- package/dist/commonjs/oauth.js +277 -0
- package/dist/commonjs/oauth.js.map +1 -0
- package/dist/commonjs/oauthCommon.d.ts +12 -0
- package/dist/commonjs/oauthCommon.d.ts.map +1 -0
- package/dist/commonjs/oauthCommon.js +26 -0
- package/dist/commonjs/oauthCommon.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/perms.d.ts +3 -0
- package/dist/commonjs/perms.d.ts.map +1 -0
- package/dist/commonjs/perms.js +66 -0
- package/dist/commonjs/perms.js.map +1 -0
- package/dist/commonjs/relationships.d.ts +7 -0
- package/dist/commonjs/relationships.d.ts.map +1 -0
- package/dist/commonjs/relationships.js +46 -0
- package/dist/commonjs/relationships.js.map +1 -0
- package/dist/commonjs/schema.d.ts +161 -0
- package/dist/commonjs/schema.d.ts.map +1 -0
- package/dist/commonjs/schema.js +174 -0
- package/dist/commonjs/schema.js.map +1 -0
- package/dist/commonjs/serverOAuth.d.ts +25 -0
- package/dist/commonjs/serverOAuth.d.ts.map +1 -0
- package/dist/commonjs/serverOAuth.js +72 -0
- package/dist/commonjs/serverOAuth.js.map +1 -0
- package/dist/commonjs/typescript-schema.d.ts +17 -0
- package/dist/commonjs/typescript-schema.d.ts.map +1 -0
- package/dist/commonjs/typescript-schema.js +314 -0
- package/dist/commonjs/typescript-schema.js.map +1 -0
- package/dist/commonjs/util.d.ts +13 -0
- package/dist/commonjs/util.d.ts.map +1 -0
- package/dist/commonjs/util.js +55 -0
- package/dist/commonjs/util.js.map +1 -0
- package/dist/commonjs/version.d.ts +3 -0
- package/dist/commonjs/version.d.ts.map +1 -0
- package/dist/commonjs/version.js +5 -0
- package/dist/commonjs/version.js.map +1 -0
- package/dist/esm/ProgressPromise.d.ts +18 -0
- package/dist/esm/ProgressPromise.d.ts.map +1 -0
- package/dist/esm/ProgressPromise.js +73 -0
- package/dist/esm/ProgressPromise.js.map +1 -0
- package/dist/esm/api.d.ts +480 -0
- package/dist/esm/api.d.ts.map +1 -0
- package/dist/esm/api.js +1121 -0
- package/dist/esm/api.js.map +1 -0
- package/dist/esm/backupDownload.d.ts +89 -0
- package/dist/esm/backupDownload.d.ts.map +1 -0
- package/dist/esm/backupDownload.js +354 -0
- package/dist/esm/backupDownload.js.map +1 -0
- package/dist/esm/backups.d.ts +146 -0
- package/dist/esm/backups.d.ts.map +1 -0
- package/dist/esm/backups.js +237 -0
- package/dist/esm/backups.js.map +1 -0
- package/dist/esm/clerk.d.ts +2 -0
- package/dist/esm/clerk.d.ts.map +1 -0
- package/dist/esm/clerk.js +26 -0
- package/dist/esm/clerk.js.map +1 -0
- package/dist/esm/consts.d.ts +11 -0
- package/dist/esm/consts.d.ts.map +1 -0
- package/dist/esm/consts.js +13 -0
- package/dist/esm/consts.js.map +1 -0
- package/dist/esm/crypto.d.ts +4 -0
- package/dist/esm/crypto.d.ts.map +1 -0
- package/dist/esm/crypto.js +21 -0
- package/dist/esm/crypto.js.map +1 -0
- package/dist/esm/index.d.ts +18 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/migrationUtils.d.ts +4 -0
- package/dist/esm/migrationUtils.d.ts.map +1 -0
- package/dist/esm/migrationUtils.js +47 -0
- package/dist/esm/migrationUtils.js.map +1 -0
- package/dist/esm/migrations.d.ts +99 -0
- package/dist/esm/migrations.d.ts.map +1 -0
- package/dist/esm/migrations.js +588 -0
- package/dist/esm/migrations.js.map +1 -0
- package/dist/esm/oauth.d.ts +98 -0
- package/dist/esm/oauth.d.ts.map +1 -0
- package/dist/esm/oauth.js +268 -0
- package/dist/esm/oauth.js.map +1 -0
- package/dist/esm/oauthCommon.d.ts +12 -0
- package/dist/esm/oauthCommon.d.ts.map +1 -0
- package/dist/esm/oauthCommon.js +22 -0
- package/dist/esm/oauthCommon.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/perms.d.ts +3 -0
- package/dist/esm/perms.d.ts.map +1 -0
- package/dist/esm/perms.js +62 -0
- package/dist/esm/perms.js.map +1 -0
- package/dist/esm/relationships.d.ts +7 -0
- package/dist/esm/relationships.d.ts.map +1 -0
- package/dist/esm/relationships.js +43 -0
- package/dist/esm/relationships.js.map +1 -0
- package/dist/esm/schema.d.ts +161 -0
- package/dist/esm/schema.d.ts.map +1 -0
- package/dist/esm/schema.js +158 -0
- package/dist/esm/schema.js.map +1 -0
- package/dist/esm/serverOAuth.d.ts +25 -0
- package/dist/esm/serverOAuth.d.ts.map +1 -0
- package/dist/esm/serverOAuth.js +68 -0
- package/dist/esm/serverOAuth.js.map +1 -0
- package/dist/esm/typescript-schema.d.ts +17 -0
- package/dist/esm/typescript-schema.d.ts.map +1 -0
- package/dist/esm/typescript-schema.js +310 -0
- package/dist/esm/typescript-schema.js.map +1 -0
- package/dist/esm/util.d.ts +13 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/util.js +46 -0
- package/dist/esm/util.js.map +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/standalone/index.js +13747 -0
- package/dist/standalone/index.umd.cjs +72 -0
- package/package.json +69 -3
- package/src/ProgressPromise.ts +97 -0
- package/src/api.ts +1903 -0
- package/src/backupDownload.ts +519 -0
- package/src/backups.ts +342 -0
- package/src/clerk.ts +24 -0
- package/src/consts.ts +22 -0
- package/src/crypto.ts +28 -0
- package/src/index.ts +147 -0
- package/src/migrationUtils.ts +56 -0
- package/src/migrations.ts +920 -0
- package/src/oauth.ts +390 -0
- package/src/oauthCommon.ts +38 -0
- package/src/perms.ts +81 -0
- package/src/relationships.ts +57 -0
- package/src/schema.ts +497 -0
- package/src/serverOAuth.ts +119 -0
- package/src/typescript-schema.ts +439 -0
- package/src/util.ts +77 -0
- package/src/version.ts +3 -0
- package/tsconfig.dev.json +14 -0
- package/tsconfig.json +14 -0
- package/vite.config.ts +19 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { test, expect } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
generatePermsTypescriptFile,
|
|
5
|
+
permsTypescriptFileToCode,
|
|
6
|
+
} from '../../src/perms';
|
|
7
|
+
|
|
8
|
+
test('generates perms file', () => {
|
|
9
|
+
expect(
|
|
10
|
+
generatePermsTypescriptFile(
|
|
11
|
+
{
|
|
12
|
+
$files: {
|
|
13
|
+
allow: {
|
|
14
|
+
view: 'isOwner',
|
|
15
|
+
create: 'isOwner',
|
|
16
|
+
},
|
|
17
|
+
bind: ['isOwner', "data.path.startsWith(auth.id + '/')"],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
'@sidekickdb/core',
|
|
21
|
+
),
|
|
22
|
+
).toEqual(`// Docs: https://sidekickdb.co/docs/permissions
|
|
23
|
+
|
|
24
|
+
import type { InstantRules } from "@sidekickdb/core";
|
|
25
|
+
|
|
26
|
+
const rules = {
|
|
27
|
+
"$files": {
|
|
28
|
+
"allow": {
|
|
29
|
+
"view": "isOwner",
|
|
30
|
+
"create": "isOwner"
|
|
31
|
+
},
|
|
32
|
+
"bind": [
|
|
33
|
+
"isOwner",
|
|
34
|
+
"data.path.startsWith(auth.id + '/')"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
} satisfies InstantRules;
|
|
38
|
+
|
|
39
|
+
export default rules;
|
|
40
|
+
`);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('generates empty perms file', () => {
|
|
44
|
+
expect(generatePermsTypescriptFile(null, '@sidekickdb/core'))
|
|
45
|
+
.toEqual(`// Docs: https://sidekickdb.co/docs/permissions
|
|
46
|
+
|
|
47
|
+
import type { InstantRules } from "@sidekickdb/core";
|
|
48
|
+
|
|
49
|
+
const rules = {
|
|
50
|
+
/**
|
|
51
|
+
* Welcome to SidekickDB's permission system!
|
|
52
|
+
* Right now your rules are empty. To start filling them in, check out the docs:
|
|
53
|
+
* https://sidekickdb.co/docs/permissions
|
|
54
|
+
*
|
|
55
|
+
* Here's an example to give you a feel:
|
|
56
|
+
* posts: {
|
|
57
|
+
* allow: {
|
|
58
|
+
* view: "true",
|
|
59
|
+
* create: "isOwner",
|
|
60
|
+
* update: "isOwner",
|
|
61
|
+
* delete: "isOwner",
|
|
62
|
+
* },
|
|
63
|
+
* bind: {"isOwner": "auth.id != null && auth.id == data.ownerId"},
|
|
64
|
+
* },
|
|
65
|
+
*/
|
|
66
|
+
} satisfies InstantRules;
|
|
67
|
+
|
|
68
|
+
export default rules;
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('readsPermsFromFile', () => {
|
|
73
|
+
const content = `// Docs: https://sidekickdb.co/docs/permissions
|
|
74
|
+
|
|
75
|
+
import type { InstantRules } from "@sidekickdb/core";
|
|
76
|
+
|
|
77
|
+
const rules = {
|
|
78
|
+
"$files": {
|
|
79
|
+
"allow": {
|
|
80
|
+
"view": "isOwner",
|
|
81
|
+
"create": "isOwner"
|
|
82
|
+
},
|
|
83
|
+
"bind": [
|
|
84
|
+
"isOwner",
|
|
85
|
+
"data.path.startsWith(auth.id + '/')"
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
} satisfies InstantRules;
|
|
89
|
+
|
|
90
|
+
export default rules;
|
|
91
|
+
`;
|
|
92
|
+
|
|
93
|
+
expect(permsTypescriptFileToCode(content, 'instant.perms.ts')).toEqual({
|
|
94
|
+
$files: {
|
|
95
|
+
allow: {
|
|
96
|
+
view: 'isOwner',
|
|
97
|
+
create: 'isOwner',
|
|
98
|
+
},
|
|
99
|
+
bind: ['isOwner', "data.path.startsWith(auth.id + '/')"],
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { test, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
buildAutoRenameSelector,
|
|
4
|
+
diffSchemas,
|
|
5
|
+
i,
|
|
6
|
+
MigrationTx,
|
|
7
|
+
MigrationTxTypes,
|
|
8
|
+
} from '../../src';
|
|
9
|
+
|
|
10
|
+
const beforeSchema = i.schema({
|
|
11
|
+
entities: {
|
|
12
|
+
animals: i.entity({
|
|
13
|
+
name: i.string(),
|
|
14
|
+
age: i.number(),
|
|
15
|
+
speccies: i.string(), // spelled wrong!
|
|
16
|
+
}),
|
|
17
|
+
},
|
|
18
|
+
links: {
|
|
19
|
+
friend: {
|
|
20
|
+
forward: {
|
|
21
|
+
has: 'many',
|
|
22
|
+
label: 'mother', // from mother -> parent
|
|
23
|
+
on: 'animals',
|
|
24
|
+
required: false,
|
|
25
|
+
},
|
|
26
|
+
reverse: {
|
|
27
|
+
has: 'many',
|
|
28
|
+
label: 'child',
|
|
29
|
+
on: 'animals',
|
|
30
|
+
required: false,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const afterSchema = i.schema({
|
|
36
|
+
entities: {
|
|
37
|
+
animals: i.entity({
|
|
38
|
+
name: i.string(),
|
|
39
|
+
age: i.number(),
|
|
40
|
+
species: i.string(), // spelled correct!
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
links: {
|
|
44
|
+
friend: {
|
|
45
|
+
forward: {
|
|
46
|
+
has: 'many',
|
|
47
|
+
label: 'parent',
|
|
48
|
+
on: 'animals',
|
|
49
|
+
required: false,
|
|
50
|
+
},
|
|
51
|
+
reverse: {
|
|
52
|
+
has: 'many',
|
|
53
|
+
label: 'child',
|
|
54
|
+
on: 'animals',
|
|
55
|
+
required: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const expectTxType = (
|
|
62
|
+
txSteps: MigrationTx[],
|
|
63
|
+
type: keyof MigrationTxTypes,
|
|
64
|
+
count?: number,
|
|
65
|
+
) => {
|
|
66
|
+
const countMatched = txSteps.filter((step) => step.type == type).length;
|
|
67
|
+
if (count) {
|
|
68
|
+
expect(countMatched).toBe(count);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
expect(countMatched).toBeGreaterThan(0);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
test('works without flags', async () => {
|
|
75
|
+
const fun = buildAutoRenameSelector([]);
|
|
76
|
+
|
|
77
|
+
const result = await diffSchemas(beforeSchema, afterSchema, fun, {});
|
|
78
|
+
|
|
79
|
+
console.log(result);
|
|
80
|
+
expectTxType(result, 'delete-attr', 2);
|
|
81
|
+
expectTxType(result, 'add-attr', 2);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('simple attr flag', async () => {
|
|
85
|
+
const fun = buildAutoRenameSelector(['animals.speccies:animals.species']);
|
|
86
|
+
|
|
87
|
+
const result = await diffSchemas(beforeSchema, afterSchema, fun, {});
|
|
88
|
+
|
|
89
|
+
console.log(result);
|
|
90
|
+
expectTxType(result, 'update-attr', 1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('simple link flag', async () => {
|
|
94
|
+
const fun = buildAutoRenameSelector(['animals.mother:animals.parent']);
|
|
95
|
+
|
|
96
|
+
const result = await diffSchemas(beforeSchema, afterSchema, fun, {});
|
|
97
|
+
|
|
98
|
+
console.log(result);
|
|
99
|
+
expectTxType(result, 'update-attr', 1);
|
|
100
|
+
expectTxType(result, 'delete-attr', 1);
|
|
101
|
+
expectTxType(result, 'add-attr', 1);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('both links and base attrs', async () => {
|
|
105
|
+
const fun = buildAutoRenameSelector([
|
|
106
|
+
'animals.speccies:animals.species',
|
|
107
|
+
'animals.mother:animals.parent',
|
|
108
|
+
]);
|
|
109
|
+
|
|
110
|
+
const result = await diffSchemas(beforeSchema, afterSchema, fun, {});
|
|
111
|
+
|
|
112
|
+
console.log(result);
|
|
113
|
+
expectTxType(result, 'update-attr', 2);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('nonexisting flag', async () => {
|
|
117
|
+
const fun = buildAutoRenameSelector([
|
|
118
|
+
'animals.favoriteFood:animals.favoriteFood',
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
const result = await diffSchemas(beforeSchema, afterSchema, fun, {});
|
|
122
|
+
|
|
123
|
+
console.log(result);
|
|
124
|
+
expectTxType(result, 'delete-attr', 2);
|
|
125
|
+
expectTxType(result, 'add-attr', 2);
|
|
126
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { describe, expect, test as baseTest } from 'vitest';
|
|
2
|
+
import { PlatformApi, ProgressPromise, i } from '../../src/index';
|
|
3
|
+
|
|
4
|
+
// SidekickDB: networked suite. It runs only against the backend named by
|
|
5
|
+
// SIDEKICK_E2E_API_URI and is skipped when that is unset; there is no default.
|
|
6
|
+
const apiURI = process.env.SIDEKICK_E2E_API_URI
|
|
7
|
+
? new URL(process.env.SIDEKICK_E2E_API_URI).href.replace(/\/+$/, '')
|
|
8
|
+
: undefined;
|
|
9
|
+
if (!apiURI) {
|
|
10
|
+
console.warn(
|
|
11
|
+
'[sidekick] Skipping schemaPush e2e: set SIDEKICK_E2E_API_URI to a SidekickDB server URL to run it.',
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const test = (apiURI ? baseTest : baseTest.skip) as typeof baseTest;
|
|
15
|
+
|
|
16
|
+
describe.concurrent('schemaPush e2e', { timeout: 20_000 }, () => {
|
|
17
|
+
for (const fnName of ['planSchemaPush', 'schemaPush'] as const) {
|
|
18
|
+
test(`${fnName}: validation errors`, async () => {
|
|
19
|
+
const initialSchema = i.schema({
|
|
20
|
+
entities: {
|
|
21
|
+
posts: i.entity({
|
|
22
|
+
name: i.string(),
|
|
23
|
+
details: i.string(),
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const tempApi = new PlatformApi({ apiURI });
|
|
29
|
+
const { app } = await tempApi.createTemporaryApp({
|
|
30
|
+
schema: initialSchema,
|
|
31
|
+
title: 'tempApp',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const overwriteSchema = i.schema({
|
|
35
|
+
entities: {
|
|
36
|
+
posts: i.entity({
|
|
37
|
+
title: i.string(),
|
|
38
|
+
slug: i.string(),
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const appApi = new PlatformApi({
|
|
43
|
+
auth: { token: app.adminToken },
|
|
44
|
+
apiURI,
|
|
45
|
+
});
|
|
46
|
+
await expect(
|
|
47
|
+
appApi[fnName](app.id, {
|
|
48
|
+
schema: overwriteSchema,
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
renames: ['posts.name:posts.title'],
|
|
51
|
+
}),
|
|
52
|
+
).rejects.toThrowError(
|
|
53
|
+
'If you pass in `renames`, you _must_ pass in `overwrite: true`',
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
await expect(
|
|
57
|
+
appApi[fnName](app.id, {
|
|
58
|
+
schema: overwriteSchema,
|
|
59
|
+
overwrite: true,
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
renames: ['posts.nameposts.title'],
|
|
62
|
+
}),
|
|
63
|
+
).rejects.toThrowError(
|
|
64
|
+
"Invalid rename command: posts.nameposts.title. We could not parse a distinct 'from' and 'to'. The structure should look like 'from:to'. For example: 'posts.name:posts.title'",
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('normal flow ignores deletes & renames', async () => {
|
|
69
|
+
const initialSchema = i.schema({
|
|
70
|
+
entities: {
|
|
71
|
+
posts: i.entity({
|
|
72
|
+
name: i.string(),
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const tempApi = new PlatformApi({ apiURI });
|
|
77
|
+
const { app } = await tempApi.createTemporaryApp({
|
|
78
|
+
schema: initialSchema,
|
|
79
|
+
title: 'tempApp',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const additiveSchema = i.schema({
|
|
83
|
+
entities: {
|
|
84
|
+
posts: i.entity({
|
|
85
|
+
title: i.string(),
|
|
86
|
+
slug: i.string(),
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const appApi = new PlatformApi({
|
|
91
|
+
auth: { token: app.adminToken },
|
|
92
|
+
apiURI,
|
|
93
|
+
});
|
|
94
|
+
const res = await appApi[fnName](app.id, {
|
|
95
|
+
schema: additiveSchema,
|
|
96
|
+
});
|
|
97
|
+
const friendlyDescs = new Set(
|
|
98
|
+
res.steps.map((s) => s.friendlyDescription),
|
|
99
|
+
);
|
|
100
|
+
expect(friendlyDescs).toEqual(
|
|
101
|
+
new Set(['Add attribute posts.slug.', 'Add attribute posts.title.']),
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('overwrite flow handles deletes and renames', async () => {
|
|
106
|
+
const initialSchema = i.schema({
|
|
107
|
+
entities: {
|
|
108
|
+
comments: i.entity({
|
|
109
|
+
body: i.string(),
|
|
110
|
+
}),
|
|
111
|
+
posts: i.entity({
|
|
112
|
+
name: i.string(),
|
|
113
|
+
details: i.string(),
|
|
114
|
+
}),
|
|
115
|
+
},
|
|
116
|
+
links: {
|
|
117
|
+
postComments: {
|
|
118
|
+
forward: { on: 'posts', has: 'many', label: 'comments' },
|
|
119
|
+
reverse: { on: 'comments', has: 'many', label: 'posts' },
|
|
120
|
+
},
|
|
121
|
+
postParents: {
|
|
122
|
+
forward: { on: 'posts', has: 'many', label: 'parentPosts' },
|
|
123
|
+
reverse: { on: 'posts', has: 'many', label: 'childPosts' },
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const tempApi = new PlatformApi({ apiURI });
|
|
129
|
+
const { app } = await tempApi.createTemporaryApp({
|
|
130
|
+
schema: initialSchema,
|
|
131
|
+
title: 'tempApp',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const overwriteSchema = i.schema({
|
|
135
|
+
entities: {
|
|
136
|
+
comments: i.entity({
|
|
137
|
+
body: i.string(),
|
|
138
|
+
}),
|
|
139
|
+
posts: i.entity({
|
|
140
|
+
title: i.string(),
|
|
141
|
+
slug: i.string(),
|
|
142
|
+
}),
|
|
143
|
+
},
|
|
144
|
+
links: {
|
|
145
|
+
postComments: {
|
|
146
|
+
forward: { on: 'posts', has: 'many', label: 'ownComments' },
|
|
147
|
+
reverse: { on: 'comments', has: 'many', label: 'posts' },
|
|
148
|
+
},
|
|
149
|
+
postParents: {
|
|
150
|
+
forward: { on: 'posts', has: 'many', label: 'parentPosts' },
|
|
151
|
+
reverse: { on: 'posts', has: 'many', label: 'childPosts' },
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const appApi = new PlatformApi({
|
|
156
|
+
auth: { token: app.adminToken },
|
|
157
|
+
apiURI,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
console.log(fnName, app.id);
|
|
161
|
+
|
|
162
|
+
const promise = appApi[fnName](app.id, {
|
|
163
|
+
schema: overwriteSchema,
|
|
164
|
+
overwrite: true,
|
|
165
|
+
renames: ['posts.name:posts.title', 'posts.comments:posts.ownComments'],
|
|
166
|
+
});
|
|
167
|
+
const res = await promise;
|
|
168
|
+
promise.then(
|
|
169
|
+
(x) => console.log('Success: ', x),
|
|
170
|
+
(x) => console.error('Error:', x),
|
|
171
|
+
);
|
|
172
|
+
const friendlyDescs = new Set(
|
|
173
|
+
res.steps.map((s) => s.friendlyDescription),
|
|
174
|
+
);
|
|
175
|
+
expect(friendlyDescs).toEqual(
|
|
176
|
+
new Set([
|
|
177
|
+
'Add attribute posts.slug.',
|
|
178
|
+
'Make posts.slug a required attribute.',
|
|
179
|
+
'Update attribute posts.title.',
|
|
180
|
+
'Update attribute posts.ownComments.',
|
|
181
|
+
'Delete attribute posts.details.',
|
|
182
|
+
]),
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
});
|