instant-cli 0.22.99-experimental.add-user-perm-rules.20792844601.1 → 0.22.99-experimental.add-user-perm-rules.20792984656.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/dist/rename.js CHANGED
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  /**
11
2
  * Build a function to resolve renames from cli rename flags
12
3
  * The diffSchemas function takes a fixed amount of arguments so we
@@ -16,75 +7,73 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
16
7
  * @returns
17
8
  */
18
9
  export function buildAutoRenameSelector(opts) {
19
- return function (created, promptData, extraInfo) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- if (!opts.rename || !Array.isArray(opts.rename)) {
22
- return created;
23
- }
24
- // Parse rename options: format is "from:to"
25
- // note that it saves backwards since we will be testing against the base
26
- // case of a created attr
27
- const renameMap = new Map();
28
- for (const renameStr of opts.rename) {
29
- const [from, to] = renameStr.split(':');
30
- if (from && to) {
31
- renameMap.set(to.trim(), from.trim());
32
- }
10
+ return async function (created, promptData, extraInfo) {
11
+ if (!opts.rename || !Array.isArray(opts.rename)) {
12
+ return created;
13
+ }
14
+ // Parse rename options: format is "from:to"
15
+ // note that it saves backwards since we will be testing against the base
16
+ // case of a created attr
17
+ const renameMap = new Map();
18
+ for (const renameStr of opts.rename) {
19
+ const [from, to] = renameStr.split(':');
20
+ if (from && to) {
21
+ renameMap.set(to.trim(), from.trim());
33
22
  }
34
- let lookupNames = [];
35
- if ((extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.type) === 'attribute' && (extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.entityName)) {
36
- lookupNames = [`${extraInfo.entityName}.${created}`];
23
+ }
24
+ let lookupNames = [];
25
+ if (extraInfo?.type === 'attribute' && extraInfo?.entityName) {
26
+ lookupNames = [`${extraInfo.entityName}.${created}`];
27
+ }
28
+ else if (extraInfo?.type === 'link') {
29
+ // Extract both forward and reverse parts
30
+ const parts = created.split('<->');
31
+ lookupNames = [parts[0], parts[1]];
32
+ }
33
+ else {
34
+ return created;
35
+ }
36
+ // Try to find a match in the rename map using the lookup names
37
+ let fromAttr = null;
38
+ for (const lookupName of lookupNames) {
39
+ if (renameMap.has(lookupName)) {
40
+ fromAttr = renameMap.get(lookupName);
41
+ break;
37
42
  }
38
- else if ((extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.type) === 'link') {
39
- // Extract both forward and reverse parts
40
- const parts = created.split('<->');
41
- lookupNames = [parts[0], parts[1]];
43
+ }
44
+ if (fromAttr) {
45
+ let fromValue;
46
+ if (extraInfo?.type === 'attribute') {
47
+ fromValue = fromAttr.split('.').pop();
42
48
  }
43
49
  else {
44
- return created;
45
- }
46
- // Try to find a match in the rename map using the lookup names
47
- let fromAttr = null;
48
- for (const lookupName of lookupNames) {
49
- if (renameMap.has(lookupName)) {
50
- fromAttr = renameMap.get(lookupName);
51
- break;
52
- }
53
- }
54
- if (fromAttr) {
55
- let fromValue;
56
- if ((extraInfo === null || extraInfo === void 0 ? void 0 : extraInfo.type) === 'attribute') {
57
- fromValue = fromAttr.split('.').pop();
50
+ const matchingItem = promptData.find((item) => {
51
+ const itemStr = typeof item === 'string' ? item : item.from;
52
+ const itemParts = itemStr.split('<->');
53
+ return itemParts[0] === fromAttr || itemParts[1] === fromAttr;
54
+ });
55
+ if (matchingItem) {
56
+ fromValue =
57
+ typeof matchingItem === 'string' ? matchingItem : matchingItem.from;
58
58
  }
59
59
  else {
60
- const matchingItem = promptData.find((item) => {
61
- const itemStr = typeof item === 'string' ? item : item.from;
62
- const itemParts = itemStr.split('<->');
63
- return itemParts[0] === fromAttr || itemParts[1] === fromAttr;
64
- });
65
- if (matchingItem) {
66
- fromValue =
67
- typeof matchingItem === 'string' ? matchingItem : matchingItem.from;
68
- }
69
- else {
70
- return created;
71
- }
60
+ return created;
72
61
  }
73
- const hasMatch = promptData.some((item) => {
74
- if (typeof item === 'string') {
75
- return item === fromValue;
76
- }
77
- else if (item.from) {
78
- return item.from === fromValue;
79
- }
80
- return false;
81
- });
82
- if (hasMatch) {
83
- return { from: fromValue, to: created };
62
+ }
63
+ const hasMatch = promptData.some((item) => {
64
+ if (typeof item === 'string') {
65
+ return item === fromValue;
66
+ }
67
+ else if (item.from) {
68
+ return item.from === fromValue;
84
69
  }
70
+ return false;
71
+ });
72
+ if (hasMatch) {
73
+ return { from: fromValue, to: created };
85
74
  }
86
- return created;
87
- });
75
+ }
76
+ return created;
88
77
  };
89
78
  }
90
79
  //# sourceMappingURL=rename.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rename.js","sourceRoot":"","sources":["../src/rename.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAI;IAC1C,OAAO,UAAgB,OAAO,EAAE,UAAU,EAAE,SAAS;;YACnD,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBAChD,OAAO,OAAO,CAAC;YACjB,CAAC;YAED,4CAA4C;YAC5C,yEAAyE;YACzE,yBAAyB;YACzB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;YAC5B,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBACpC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,SAAS,CA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chemas function takes a fixed amount of arguments so we\n * return a function from a function here\n * exported for tests only\n * @param {*} opts program arguments from commander\n * @returns\n */\nexport function buildAutoRenameSelector(opts) {\n return async function (created, promptData, extraInfo) {\n if (!opts.rename || !Array.isArray(opts.rename)) {\n return created;\n }\n\n // Parse rename options: format is \"from:to\"\n // note that it saves backwards since we will be testing against the base\n // case of a created attr\n const renameMap = new Map();\n for (const renameStr of opts.rename) {\n const [from, to] = renameStr.split(':');\n if (from && to) {\n renameMap.set(to.trim(), from.trim());\n }\n }\n\n let lookupNames: string[] = [];\n if (extraInfo?.type === 'attribute' && extraInfo?.entityName) {\n lookupNames = [`${extraInfo.entityName}.${created}`];\n } else if (extraInfo?.type === 'link') {\n // Extract both forward and reverse parts\n const parts = created.split('<->');\n lookupNames = [parts[0], parts[1]];\n } else {\n return created;\n }\n\n // Try to find a match in the rename map using the lookup names\n let fromAttr: string | null = null;\n for (const lookupName of lookupNames) {\n if (renameMap.has(lookupName)) {\n fromAttr = renameMap.get(lookupName);\n break;\n }\n }\n\n if (fromAttr) {\n let fromValue;\n if (extraInfo?.type === 'attribute') {\n fromValue = fromAttr.split('.').pop();\n } else {\n const matchingItem = promptData.find((item) => {\n const itemStr = typeof item === 'string' ? item : item.from;\n const itemParts = itemStr.split('<->');\n return itemParts[0] === fromAttr || itemParts[1] === fromAttr;\n });\n\n if (matchingItem) {\n fromValue =\n typeof matchingItem === 'string' ? matchingItem : matchingItem.from;\n } else {\n return created;\n }\n }\n\n const hasMatch = promptData.some((item) => {\n if (typeof item === 'string') {\n return item === fromValue;\n } else if (item.from) {\n return item.from === fromValue;\n }\n return false;\n });\n\n if (hasMatch) {\n return { from: fromValue, to: created };\n }\n }\n\n return created;\n };\n}\n"]}
1
+ {"version":3,"file":"rename.js","sourceRoot":"","sources":["../src/rename.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAI;IAC1C,OAAO,KAAK,WAAW,OAAO,EAAE,UAA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,QAAQ,EAAE,CAAC;gBACb,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;YAC1C,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Build a function to resolve renames from cli rename flags\n * The diffSchemas function takes a fixed amount of arguments so we\n * return a function from a function here\n * exported for tests only\n * @param {*} opts program arguments from commander\n * @returns\n */\nexport function buildAutoRenameSelector(opts) {\n return async function (created, promptData, extraInfo) {\n if (!opts.rename || !Array.isArray(opts.rename)) {\n return created;\n }\n\n // Parse rename options: format is \"from:to\"\n // note that it saves backwards since we will be testing against the base\n // case of a created attr\n const renameMap = new Map();\n for (const renameStr of opts.rename) {\n const [from, to] = renameStr.split(':');\n if (from && to) {\n renameMap.set(to.trim(), from.trim());\n }\n }\n\n let lookupNames: string[] = [];\n if (extraInfo?.type === 'attribute' && extraInfo?.entityName) {\n lookupNames = [`${extraInfo.entityName}.${created}`];\n } else if (extraInfo?.type === 'link') {\n // Extract both forward and reverse parts\n const parts = created.split('<->');\n lookupNames = [parts[0], parts[1]];\n } else {\n return created;\n }\n\n // Try to find a match in the rename map using the lookup names\n let fromAttr: string | null = null;\n for (const lookupName of lookupNames) {\n if (renameMap.has(lookupName)) {\n fromAttr = renameMap.get(lookupName);\n break;\n }\n }\n\n if (fromAttr) {\n let fromValue;\n if (extraInfo?.type === 'attribute') {\n fromValue = fromAttr.split('.').pop();\n } else {\n const matchingItem = promptData.find((item) => {\n const itemStr = typeof item === 'string' ? item : item.from;\n const itemParts = itemStr.split('<->');\n return itemParts[0] === fromAttr || itemParts[1] === fromAttr;\n });\n\n if (matchingItem) {\n fromValue =\n typeof matchingItem === 'string' ? matchingItem : matchingItem.from;\n } else {\n return created;\n }\n }\n\n const hasMatch = promptData.some((item) => {\n if (typeof item === 'string') {\n return item === fromValue;\n } else if (item.from) {\n return item.from === fromValue;\n }\n return false;\n });\n\n if (hasMatch) {\n return { from: fromValue, to: created };\n }\n }\n\n return created;\n };\n}\n"]}
@@ -1,17 +1,7 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import chalk from 'chalk';
11
2
  import stripAnsi from 'strip-ansi';
12
3
  import { promptOk } from './util/promptOk.js';
13
4
  const renderLinkUpdate = (tx, possiblePrevAttrs) => {
14
- var _a, _b, _c;
15
5
  if (tx.partialAttr['value-type'] !== 'ref') {
16
6
  throw new Error('Invalid value type for link update');
17
7
  }
@@ -22,7 +12,7 @@ const renderLinkUpdate = (tx, possiblePrevAttrs) => {
22
12
  }) || null
23
13
  : null;
24
14
  let changeType = 'UPDATE';
25
- if (((_a = tx.partialAttr['forward-identity']) === null || _a === void 0 ? void 0 : _a.attrName) &&
15
+ if (tx.partialAttr['forward-identity']?.attrName &&
26
16
  tx.identifier.attrName !== tx.partialAttr['forward-identity'].attrName) {
27
17
  changeType = 'RENAME';
28
18
  }
@@ -30,8 +20,8 @@ const renderLinkUpdate = (tx, possiblePrevAttrs) => {
30
20
  let reverseLabel = '';
31
21
  if (oldAttr) {
32
22
  // Check for reverse rename
33
- if (((_b = tx.partialAttr['reverse-identity']) === null || _b === void 0 ? void 0 : _b.attrName) &&
34
- ((_c = oldAttr['reverse-identity']) === null || _c === void 0 ? void 0 : _c[2]) !==
23
+ if (tx.partialAttr['reverse-identity']?.attrName &&
24
+ oldAttr['reverse-identity']?.[2] !==
35
25
  tx.partialAttr['reverse-identity'].attrName) {
36
26
  changeType = 'RENAME REVERSE';
37
27
  }
@@ -120,10 +110,10 @@ export const groupSteps = (steps) => {
120
110
  });
121
111
  return [...collapsed, ...otherSteps];
122
112
  };
123
- export const confirmImportantSteps = (planSteps) => __awaiter(void 0, void 0, void 0, function* () {
113
+ export const confirmImportantSteps = async (planSteps) => {
124
114
  for (const step of planSteps) {
125
115
  if (step.type === 'delete-namespace') {
126
- const ok = yield promptOk({
116
+ const ok = await promptOk({
127
117
  promptText: `Are you sure you want to delete namespace ${step.namespace}?`,
128
118
  });
129
119
  if (!ok) {
@@ -131,17 +121,15 @@ export const confirmImportantSteps = (planSteps) => __awaiter(void 0, void 0, vo
131
121
  }
132
122
  }
133
123
  }
134
- });
124
+ };
135
125
  const createDotName = (step) => {
136
126
  return `${step.identifier.namespace}.${step.identifier.attrName}`;
137
127
  };
138
128
  const isRename = (step) => {
139
- var _a, _b;
140
- return (((_a = step.partialAttr['forward-identity']) === null || _a === void 0 ? void 0 : _a.attrName) &&
141
- ((_b = step.partialAttr['forward-identity']) === null || _b === void 0 ? void 0 : _b.attrName) !== step.identifier.attrName);
129
+ return (step.partialAttr['forward-identity']?.attrName &&
130
+ step.partialAttr['forward-identity']?.attrName !== step.identifier.attrName);
142
131
  };
143
132
  export const renderSchemaPlan = (planSteps, prevAttrs) => {
144
- var _a, _b;
145
133
  const result = [];
146
134
  const addLine = (line) => {
147
135
  result.push(line);
@@ -189,7 +177,7 @@ export const renderSchemaPlan = (planSteps, prevAttrs) => {
189
177
  attr['forward-identity'][2] === step.identifier.attrName);
190
178
  }) || null
191
179
  : null;
192
- if ((oldAttr === null || oldAttr === void 0 ? void 0 : oldAttr['value-type']) === 'ref') {
180
+ if (oldAttr?.['value-type'] === 'ref') {
193
181
  addLine(`${chalk.bgRed(' - DELETE LINK ')} ${step.identifier.namespace}.${step.identifier.attrName}`);
194
182
  break;
195
183
  }
@@ -201,7 +189,7 @@ export const renderSchemaPlan = (planSteps, prevAttrs) => {
201
189
  }
202
190
  else {
203
191
  if (isRename(step)) {
204
- addLine(`${chalk.bgYellow.black(' * RENAME ATTR ')} ${createDotName(step)} -> ${(_a = step.partialAttr['forward-identity']) === null || _a === void 0 ? void 0 : _a['namespace']}.${(_b = step.partialAttr['forward-identity']) === null || _b === void 0 ? void 0 : _b['attrName']}`);
192
+ addLine(`${chalk.bgYellow.black(' * RENAME ATTR ')} ${createDotName(step)} -> ${step.partialAttr['forward-identity']?.['namespace']}.${step.partialAttr['forward-identity']?.['attrName']}`);
205
193
  }
206
194
  else {
207
195
  addLine(`${chalk.bgYellow.black(' * UPDATE ATTR ')} ${createDotName(step)}`);
@@ -1 +1 @@
1
- {"version":3,"file":"renderSchemaPlan.js","sourceRoot":"","sources":["../src/renderSchemaPlan.ts"],"names":[],"mappings":";;;;;;;;;AAMA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAK9C,MAAM,gBAAgB,GAAG,CACvB,EAAmC,EACnC,iBAAmC,EAC3B,EAAE;;IACV,IAAI,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,KAAK,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,OAAO,GAAG,iBAAiB;QAC/B,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YAC9B,OAAO,CACL,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,SAAS;gBACvD,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,UAAU,CAAC,QAAQ,CACvD,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI;QACZ,CAAC,CAAC,IAAI,CAAC;IAET,IAAI,UAAU,GAA2C,QAAQ,CAAC;IAElE,IACE,CAAA,MAAA,EAAE,CAA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CAAC,KAAK,CAAC,6BAA6B,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAC9E,CAAC;gBACF,MAAM;YACR,KAAK,iBAAiB;gBACpB,OAAO,CACL,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAC5G,CAAC;gBACF,MAAM;YACR,KAAK,kBAAkB;gBACrB,OAAO,CACL,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAClF,CAAC;gBACF,MAAM;YAER;gBACE,MAAM,WAAW,GAAU,IAAI,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import {\n convertTxSteps,\n MigrationTx,\n MigrationTxSpecific,\n MigrationTxTypes,\n} from '@instantdb/platform';\nimport chalk from 'chalk';\nimport stripAnsi from 'strip-ansi';\nimport { promptOk } from './util/promptOk.js';\n\n// Hack to prevent using @instantdb/core as a dependency for cli\ntype InstantDBAttr = Parameters<typeof convertTxSteps>[1][0];\n\nconst renderLinkUpdate = (\n tx: MigrationTxTypes['update-attr'],\n possiblePrevAttrs?: InstantDBAttr[],\n): string => {\n if (tx.partialAttr['value-type'] !== 'ref') {\n throw new Error('Invalid value type for link update');\n }\n\n const oldAttr = possiblePrevAttrs\n ? possiblePrevAttrs.find((attr) => {\n return (\n attr['forward-identity'][1] === tx.identifier.namespace &&\n attr['forward-identity'][2] === tx.identifier.attrName\n );\n }) || null\n : null;\n\n let changeType: 'UPDATE' | 'RENAME' | 'RENAME REVERSE' = 'UPDATE';\n\n if (\n tx.partialAttr['forward-identity']?.attrName &&\n tx.identifier.attrName !== tx.partialAttr['forward-identity'].attrName\n ) {\n changeType = 'RENAME';\n }\n\n const details: string[] = [];\n let reverseLabel = '';\n if (oldAttr) {\n // Check for reverse rename\n if (\n tx.partialAttr['reverse-identity']?.attrName &&\n oldAttr['reverse-identity']?.[2] !==\n tx.partialAttr['reverse-identity'].attrName\n ) {\n changeType = 'RENAME REVERSE';\n }\n\n reverseLabel = ` <-> ${oldAttr['reverse-identity']![1]}.${oldAttr['reverse-identity']![2]}`;\n\n if (!oldAttr['on-delete'] && tx.partialAttr['on-delete']) {\n details.push(\n `(SET ON DELETE ${oldAttr['reverse-identity']![1]} CASCADE DELETE ${oldAttr['forward-identity'][1]})`,\n );\n }\n if (!oldAttr['on-delete-reverse'] && tx.partialAttr['on-delete-reverse']) {\n details.push(\n `(SET ON DELETE ${oldAttr['forward-identity']![1]} CASCADE DELETE ${oldAttr['reverse-identity']![1]})`,\n );\n }\n if (oldAttr['on-delete'] && !oldAttr['on-delete-reverse']) {\n details.push(\n `(REMOVE CASCADE DELETE ON ${oldAttr['reverse-identity']![1]})`,\n );\n }\n if (oldAttr['on-delete-reverse'] && !oldAttr['on-delete-reverse']) {\n details.push(\n `(REMOVE REVERSE CASCADE DELETE ON ${oldAttr['forward-identity'][1]})`,\n );\n }\n }\n\n return `${chalk.bgYellow.black(` * ${changeType} ATTR `)} ${tx.identifier.namespace}.${tx.identifier.attrName}${reverseLabel} ${details.join(' ')}`;\n};\n\nexport class CancelSchemaError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CancelSchemaError';\n }\n}\n\nconst getRelationship = (\n cardinality: 'one' | 'many',\n unique: boolean,\n): string[] => {\n if (cardinality === 'many' && !unique) return ['many', 'many'];\n if (cardinality === 'one' && unique) return ['one', 'one'];\n if (cardinality === 'many' && unique) return ['many', 'one'];\n if (cardinality === 'one' && !unique) return ['one', 'many'];\n throw new Error('Invalid relationship');\n};\n\ntype AddOrDeleteAttr =\n | MigrationTxSpecific<'add-attr'>\n | MigrationTxSpecific<'delete-attr'>;\n\ntype SuperMigrationTx =\n | MigrationTx\n | { type: 'create-namespace'; namespace: string; innerSteps: MigrationTx[] }\n | { type: 'delete-namespace'; namespace: string; innerSteps: MigrationTx[] };\n\nexport const groupSteps = (steps: MigrationTx[]): SuperMigrationTx[] => {\n const { addOrDelSteps, otherSteps } = steps.reduce(\n (acc, step) => {\n if (step.type === 'add-attr' || step.type === 'delete-attr') {\n acc.addOrDelSteps.push(step);\n } else {\n acc.otherSteps.push(step);\n }\n return acc;\n },\n { addOrDelSteps: [] as AddOrDeleteAttr[], otherSteps: [] as MigrationTx[] },\n );\n // Group by namespace\n const groupedAddOrDel = addOrDelSteps.reduce(\n (acc, step) => {\n const namespace = step.identifier.namespace;\n if (!acc[namespace]) {\n acc[namespace] = [];\n }\n acc[namespace].push(step);\n return acc;\n },\n {} as Record<string, MigrationTx[]>,\n );\n\n const collapsed: SuperMigrationTx[] = Object.values(groupedAddOrDel).flatMap(\n (namedGroup) => {\n const isWholeEntityBeingDeleted = namedGroup.some((step) => {\n if (step.type === 'delete-attr' && step.identifier.attrName === 'id') {\n return true;\n }\n });\n\n if (isWholeEntityBeingDeleted) {\n return [\n {\n type: 'delete-namespace',\n namespace: namedGroup[0].identifier.namespace,\n innerSteps: namedGroup,\n } satisfies SuperMigrationTx as SuperMigrationTx,\n ];\n }\n\n const isWholeEntityBeingCreated = namedGroup.some((step) => {\n if (step.type === 'add-attr' && step.identifier.attrName === 'id') {\n return true;\n }\n });\n\n if (isWholeEntityBeingCreated) {\n return [\n {\n type: 'create-namespace',\n namespace: namedGroup[0].identifier.namespace,\n innerSteps: namedGroup,\n } satisfies SuperMigrationTx as SuperMigrationTx,\n ];\n }\n\n return namedGroup;\n },\n );\n\n return [...collapsed, ...otherSteps];\n};\n\nexport const confirmImportantSteps = async (planSteps: SuperMigrationTx[]) => {\n for (const step of planSteps) {\n if (step.type === 'delete-namespace') {\n const ok = await promptOk({\n promptText: `Are you sure you want to delete namespace ${step.namespace}?`,\n });\n if (!ok) {\n throw new CancelSchemaError(`Deletion of namespace ${step.namespace}`);\n }\n }\n }\n};\n\nconst createDotName = (step: MigrationTx) => {\n return `${step.identifier.namespace}.${step.identifier.attrName}`;\n};\n\nconst isRename = (step: MigrationTxSpecific<'update-attr'>) => {\n return (\n step.partialAttr['forward-identity']?.attrName &&\n step.partialAttr['forward-identity']?.attrName !== step.identifier.attrName\n );\n};\n\nexport const renderSchemaPlan = (\n planSteps: SuperMigrationTx[],\n prevAttrs?: InstantDBAttr[],\n): string[] => {\n const result: string[] = [];\n\n const addLine = (line: string) => {\n result.push(line);\n };\n\n const addSecondaryLine = (line: string) => {\n addLine(` ${chalk.italic(chalk.gray(stripAnsi(line)))}`);\n };\n\n for (const step of planSteps) {\n switch (step.type) {\n case 'create-namespace':\n addLine(\n `${chalk.bgGreen.black(' + CREATE NAMESPACE ')} ${step.namespace}`,\n );\n renderSchemaPlan(step.innerSteps, prevAttrs).forEach((outputLine) =>\n addSecondaryLine(outputLine),\n );\n break;\n case 'delete-namespace':\n addLine(`${chalk.bgRed(' - DELETE NAMESPACE ')} ${step.namespace}`);\n break;\n case 'add-attr':\n if (step['value-type'] === 'ref' && step['reverse-identity']) {\n addLine(\n `${chalk.bgGreen.black(' + CREATE LINK ')} ${createDotName(step)} <-> ${step['reverse-identity'].namespace}.${step['reverse-identity'].attrName}`,\n );\n addSecondaryLine(\n ' ' +\n getRelationship(step.cardinality, step['unique?'])\n .join(' <-> ')\n .toUpperCase(),\n );\n } else {\n addLine(\n `${chalk.bgGreen.black(' + CREATE ATTR ')} ${createDotName(step)}`,\n );\n if (step['checked-data-type']) {\n addSecondaryLine(' DATA TYPE: ' + step['checked-data-type']);\n }\n if (step['unique?'] && step.identifier.attrName !== 'id') {\n addSecondaryLine(' UNIQUE');\n }\n if (!step['required?']) {\n addSecondaryLine(' OPTIONAL');\n }\n if (step['index?']) {\n addSecondaryLine(' INDEXED');\n }\n }\n break;\n case 'delete-attr':\n const oldAttr = prevAttrs\n ? prevAttrs.find((attr) => {\n return (\n attr['forward-identity'][1] === step.identifier.namespace &&\n attr['forward-identity'][2] === step.identifier.attrName\n );\n }) || null\n : null;\n\n if (oldAttr?.['value-type'] === 'ref') {\n addLine(\n `${chalk.bgRed(' - DELETE LINK ')} ${step.identifier.namespace}.${step.identifier.attrName}`,\n );\n break;\n }\n\n addLine(`${chalk.bgRed(' - DELETE ATTR ')} ${createDotName(step)}`);\n break;\n case 'update-attr':\n if (step.partialAttr['value-type'] === 'ref') {\n addLine(renderLinkUpdate(step, prevAttrs));\n } else {\n if (isRename(step)) {\n addLine(\n `${chalk.bgYellow.black(' * RENAME ATTR ')} ${createDotName(step)} -> ${step.partialAttr['forward-identity']?.['namespace']}.${step.partialAttr['forward-identity']?.['attrName']}`,\n );\n } else {\n addLine(\n `${chalk.bgYellow.black(' * UPDATE ATTR ')} ${createDotName(step)}`,\n );\n }\n }\n break;\n case 'index':\n addLine(\n `${chalk.bgBlue.black(' + CREATE INDEX ')} ${createDotName(step)}`,\n );\n break;\n case 'remove-index':\n addLine(\n `${chalk.bgBlue.black(' - DELETE INDEX ')} ${createDotName(step)}`,\n );\n break;\n case 'required':\n addLine(\n `${chalk.bgBlue.black(' + MAKE REQUIRED ')} ${createDotName(step)}`,\n );\n break;\n case 'unique':\n addLine(\n `${chalk.bgBlue.black(' * MAKE UNIQUE ')} ${createDotName(step)}`,\n );\n break;\n case 'remove-required':\n addLine(\n `${chalk.bgBlue.black(' - MAKE OPTIONAL ')} ${createDotName(step)}`,\n );\n break;\n case 'remove-unique':\n addLine(\n `${chalk.bgBlue.black(' - REMOVE UNIQUE CONSTRAINT')} ${createDotName(step)}`,\n );\n break;\n case 'check-data-type':\n addLine(\n `${chalk.bgBlue.black(' + SET DATA TYPE ')} ${createDotName(step)} ${chalk.dim(step['checked-data-type'])}`,\n );\n break;\n case 'remove-data-type':\n addLine(\n `${chalk.bgBlue.black(' - REMOVE DATA TYPE CONSTRAINT ')} ${createDotName(step)}`,\n );\n break;\n\n default:\n const unknownStep: never = step;\n }\n }\n\n return result;\n};\n"]}
1
+ {"version":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U,IAAI,CAAC;QACpC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import {\n convertTxSteps,\n MigrationTx,\n MigrationTxSpecific,\n MigrationTxTypes,\n} from '@instantdb/platform';\nimport chalk from 'chalk';\nimport stripAnsi from 'strip-ansi';\nimport { promptOk } from './util/promptOk.js';\n\n// Hack to prevent using @instantdb/core as a dependency for cli\ntype InstantDBAttr = Parameters<typeof convertTxSteps>[1][0];\n\nconst renderLinkUpdate = (\n tx: MigrationTxTypes['update-attr'],\n possiblePrevAttrs?: InstantDBAttr[],\n): string => {\n if (tx.partialAttr['value-type'] !== 'ref') {\n throw new Error('Invalid value type for link update');\n }\n\n const oldAttr = possiblePrevAttrs\n ? possiblePrevAttrs.find((attr) => {\n return (\n attr['forward-identity'][1] === tx.identifier.namespace &&\n attr['forward-identity'][2] === tx.identifier.attrName\n );\n }) || null\n : null;\n\n let changeType: 'UPDATE' | 'RENAME' | 'RENAME REVERSE' = 'UPDATE';\n\n if (\n tx.partialAttr['forward-identity']?.attrName &&\n tx.identifier.attrName !== tx.partialAttr['forward-identity'].attrName\n ) {\n changeType = 'RENAME';\n }\n\n const details: string[] = [];\n let reverseLabel = '';\n if (oldAttr) {\n // Check for reverse rename\n if (\n tx.partialAttr['reverse-identity']?.attrName &&\n oldAttr['reverse-identity']?.[2] !==\n tx.partialAttr['reverse-identity'].attrName\n ) {\n changeType = 'RENAME REVERSE';\n }\n\n reverseLabel = ` <-> ${oldAttr['reverse-identity']![1]}.${oldAttr['reverse-identity']![2]}`;\n\n if (!oldAttr['on-delete'] && tx.partialAttr['on-delete']) {\n details.push(\n `(SET ON DELETE ${oldAttr['reverse-identity']![1]} CASCADE DELETE ${oldAttr['forward-identity'][1]})`,\n );\n }\n if (!oldAttr['on-delete-reverse'] && tx.partialAttr['on-delete-reverse']) {\n details.push(\n `(SET ON DELETE ${oldAttr['forward-identity']![1]} CASCADE DELETE ${oldAttr['reverse-identity']![1]})`,\n );\n }\n if (oldAttr['on-delete'] && !oldAttr['on-delete-reverse']) {\n details.push(\n `(REMOVE CASCADE DELETE ON ${oldAttr['reverse-identity']![1]})`,\n );\n }\n if (oldAttr['on-delete-reverse'] && !oldAttr['on-delete-reverse']) {\n details.push(\n `(REMOVE REVERSE CASCADE DELETE ON ${oldAttr['forward-identity'][1]})`,\n );\n }\n }\n\n return `${chalk.bgYellow.black(` * ${changeType} ATTR `)} ${tx.identifier.namespace}.${tx.identifier.attrName}${reverseLabel} ${details.join(' ')}`;\n};\n\nexport class CancelSchemaError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CancelSchemaError';\n }\n}\n\nconst getRelationship = (\n cardinality: 'one' | 'many',\n unique: boolean,\n): string[] => {\n if (cardinality === 'many' && !unique) return ['many', 'many'];\n if (cardinality === 'one' && unique) return ['one', 'one'];\n if (cardinality === 'many' && unique) return ['many', 'one'];\n if (cardinality === 'one' && !unique) return ['one', 'many'];\n throw new Error('Invalid relationship');\n};\n\ntype AddOrDeleteAttr =\n | MigrationTxSpecific<'add-attr'>\n | MigrationTxSpecific<'delete-attr'>;\n\ntype SuperMigrationTx =\n | MigrationTx\n | { type: 'create-namespace'; namespace: string; innerSteps: MigrationTx[] }\n | { type: 'delete-namespace'; namespace: string; innerSteps: MigrationTx[] };\n\nexport const groupSteps = (steps: MigrationTx[]): SuperMigrationTx[] => {\n const { addOrDelSteps, otherSteps } = steps.reduce(\n (acc, step) => {\n if (step.type === 'add-attr' || step.type === 'delete-attr') {\n acc.addOrDelSteps.push(step);\n } else {\n acc.otherSteps.push(step);\n }\n return acc;\n },\n { addOrDelSteps: [] as AddOrDeleteAttr[], otherSteps: [] as MigrationTx[] },\n );\n // Group by namespace\n const groupedAddOrDel = addOrDelSteps.reduce(\n (acc, step) => {\n const namespace = step.identifier.namespace;\n if (!acc[namespace]) {\n acc[namespace] = [];\n }\n acc[namespace].push(step);\n return acc;\n },\n {} as Record<string, MigrationTx[]>,\n );\n\n const collapsed: SuperMigrationTx[] = Object.values(groupedAddOrDel).flatMap(\n (namedGroup) => {\n const isWholeEntityBeingDeleted = namedGroup.some((step) => {\n if (step.type === 'delete-attr' && step.identifier.attrName === 'id') {\n return true;\n }\n });\n\n if (isWholeEntityBeingDeleted) {\n return [\n {\n type: 'delete-namespace',\n namespace: namedGroup[0].identifier.namespace,\n innerSteps: namedGroup,\n } satisfies SuperMigrationTx as SuperMigrationTx,\n ];\n }\n\n const isWholeEntityBeingCreated = namedGroup.some((step) => {\n if (step.type === 'add-attr' && step.identifier.attrName === 'id') {\n return true;\n }\n });\n\n if (isWholeEntityBeingCreated) {\n return [\n {\n type: 'create-namespace',\n namespace: namedGroup[0].identifier.namespace,\n innerSteps: namedGroup,\n } satisfies SuperMigrationTx as SuperMigrationTx,\n ];\n }\n\n return namedGroup;\n },\n );\n\n return [...collapsed, ...otherSteps];\n};\n\nexport const confirmImportantSteps = async (planSteps: SuperMigrationTx[]) => {\n for (const step of planSteps) {\n if (step.type === 'delete-namespace') {\n const ok = await promptOk({\n promptText: `Are you sure you want to delete namespace ${step.namespace}?`,\n });\n if (!ok) {\n throw new CancelSchemaError(`Deletion of namespace ${step.namespace}`);\n }\n }\n }\n};\n\nconst createDotName = (step: MigrationTx) => {\n return `${step.identifier.namespace}.${step.identifier.attrName}`;\n};\n\nconst isRename = (step: MigrationTxSpecific<'update-attr'>) => {\n return (\n step.partialAttr['forward-identity']?.attrName &&\n step.partialAttr['forward-identity']?.attrName !== step.identifier.attrName\n );\n};\n\nexport const renderSchemaPlan = (\n planSteps: SuperMigrationTx[],\n prevAttrs?: InstantDBAttr[],\n): string[] => {\n const result: string[] = [];\n\n const addLine = (line: string) => {\n result.push(line);\n };\n\n const addSecondaryLine = (line: string) => {\n addLine(` ${chalk.italic(chalk.gray(stripAnsi(line)))}`);\n };\n\n for (const step of planSteps) {\n switch (step.type) {\n case 'create-namespace':\n addLine(\n `${chalk.bgGreen.black(' + CREATE NAMESPACE ')} ${step.namespace}`,\n );\n renderSchemaPlan(step.innerSteps, prevAttrs).forEach((outputLine) =>\n addSecondaryLine(outputLine),\n );\n break;\n case 'delete-namespace':\n addLine(`${chalk.bgRed(' - DELETE NAMESPACE ')} ${step.namespace}`);\n break;\n case 'add-attr':\n if (step['value-type'] === 'ref' && step['reverse-identity']) {\n addLine(\n `${chalk.bgGreen.black(' + CREATE LINK ')} ${createDotName(step)} <-> ${step['reverse-identity'].namespace}.${step['reverse-identity'].attrName}`,\n );\n addSecondaryLine(\n ' ' +\n getRelationship(step.cardinality, step['unique?'])\n .join(' <-> ')\n .toUpperCase(),\n );\n } else {\n addLine(\n `${chalk.bgGreen.black(' + CREATE ATTR ')} ${createDotName(step)}`,\n );\n if (step['checked-data-type']) {\n addSecondaryLine(' DATA TYPE: ' + step['checked-data-type']);\n }\n if (step['unique?'] && step.identifier.attrName !== 'id') {\n addSecondaryLine(' UNIQUE');\n }\n if (!step['required?']) {\n addSecondaryLine(' OPTIONAL');\n }\n if (step['index?']) {\n addSecondaryLine(' INDEXED');\n }\n }\n break;\n case 'delete-attr':\n const oldAttr = prevAttrs\n ? prevAttrs.find((attr) => {\n return (\n attr['forward-identity'][1] === step.identifier.namespace &&\n attr['forward-identity'][2] === step.identifier.attrName\n );\n }) || null\n : null;\n\n if (oldAttr?.['value-type'] === 'ref') {\n addLine(\n `${chalk.bgRed(' - DELETE LINK ')} ${step.identifier.namespace}.${step.identifier.attrName}`,\n );\n break;\n }\n\n addLine(`${chalk.bgRed(' - DELETE ATTR ')} ${createDotName(step)}`);\n break;\n case 'update-attr':\n if (step.partialAttr['value-type'] === 'ref') {\n addLine(renderLinkUpdate(step, prevAttrs));\n } else {\n if (isRename(step)) {\n addLine(\n `${chalk.bgYellow.black(' * RENAME ATTR ')} ${createDotName(step)} -> ${step.partialAttr['forward-identity']?.['namespace']}.${step.partialAttr['forward-identity']?.['attrName']}`,\n );\n } else {\n addLine(\n `${chalk.bgYellow.black(' * UPDATE ATTR ')} ${createDotName(step)}`,\n );\n }\n }\n break;\n case 'index':\n addLine(\n `${chalk.bgBlue.black(' + CREATE INDEX ')} ${createDotName(step)}`,\n );\n break;\n case 'remove-index':\n addLine(\n `${chalk.bgBlue.black(' - DELETE INDEX ')} ${createDotName(step)}`,\n );\n break;\n case 'required':\n addLine(\n `${chalk.bgBlue.black(' + MAKE REQUIRED ')} ${createDotName(step)}`,\n );\n break;\n case 'unique':\n addLine(\n `${chalk.bgBlue.black(' * MAKE UNIQUE ')} ${createDotName(step)}`,\n );\n break;\n case 'remove-required':\n addLine(\n `${chalk.bgBlue.black(' - MAKE OPTIONAL ')} ${createDotName(step)}`,\n );\n break;\n case 'remove-unique':\n addLine(\n `${chalk.bgBlue.black(' - REMOVE UNIQUE CONSTRAINT')} ${createDotName(step)}`,\n );\n break;\n case 'check-data-type':\n addLine(\n `${chalk.bgBlue.black(' + SET DATA TYPE ')} ${createDotName(step)} ${chalk.dim(step['checked-data-type'])}`,\n );\n break;\n case 'remove-data-type':\n addLine(\n `${chalk.bgBlue.black(' - REMOVE DATA TYPE CONSTRAINT ')} ${createDotName(step)}`,\n );\n break;\n\n default:\n const unknownStep: never = step;\n }\n }\n\n return result;\n};\n"]}