@diagonal-hq/cli 0.14.0 → 0.14.2
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/README.md +9 -8
- package/dist/cli.mjs +226 -32
- package/dist/fields.generated.d.ts +5 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,16 +74,16 @@ The build reads each file with a parser. It runs only the workflow tests.
|
|
|
74
74
|
|
|
75
75
|
## Definition uids and slugs
|
|
76
76
|
|
|
77
|
-
A definition can have two identity options. A resource, a page, a workflow `config`, a notification type, a notification template, an email layout, and the front matter of a skill file have a `uid`. No definition uses `slug` yet.
|
|
77
|
+
A definition can have two identity options. A resource, a field, a relation inverse, a page, a workflow `config`, a notification type, a notification template, an email layout, and the front matter of a skill file have a `uid`. No definition uses `slug` yet.
|
|
78
78
|
|
|
79
|
-
- `uid` is the stable identity of the definition. Its value is a lowercase UUID string literal, such as `uid: '
|
|
79
|
+
- `uid` is the stable identity of the definition. Its value is a lowercase UUID string literal, such as `uid: '019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e'`. In skill front matter, it is a YAML string, such as `uid: 019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e`. A file move, a file rename, or a name change keeps the uid. Do not change a uid.
|
|
80
80
|
- `slug` is the editable, user-facing name of the definition. It is kebab-case: lowercase letters and digits in groups that one `-` joins, such as `job-postings`. A slug change keeps the uid.
|
|
81
81
|
|
|
82
|
-
`diagonal check` writes a new uid into each definition that has none. It adds `uid: '<uuid>'` as the first option of the `defineX()` object or of the `export const config` object of a workflow, or `uid: <uuid>` as the first line of the front matter of a skill file, and leaves the rest of the file unchanged. Commit the change.
|
|
82
|
+
`diagonal check` writes a new uid into each definition that has none. It adds `uid: '<uuid>'` as the first option of the `defineX()` object, of each `field.<type>({...})` call and `settings.inverse` object, or of the `export const config` object of a workflow, or `uid: <uuid>` as the first line of the front matter of a skill file, and leaves the rest of the file unchanged. Commit the change.
|
|
83
83
|
|
|
84
84
|
The platform writes the missing uids too: a save in Files, and every other commit that the platform makes, adds a uid to each definition of the changed files that has none. A git push does not, so a pushed definition without a uid fails the deploy, and the error tells you to run `diagonal check`.
|
|
85
85
|
|
|
86
|
-
A uid is unique among the definitions of one type. Two definitions of one type with one uid are an error at the second
|
|
86
|
+
A uid is unique among the definitions of one type. A field uid is unique in its resource, and an inverse field counts as a field of its target resource. Two definitions of one type with one uid are an error at the second definition, and the error names the first file. The check does not replace a duplicate uid. When you copy a definition file, delete its `uid` and run `diagonal check`. A uid that is not a lowercase UUID is an error.
|
|
87
87
|
|
|
88
88
|
## Page bindings and seo
|
|
89
89
|
|
|
@@ -245,7 +245,7 @@ import { Resources } from '@app/generated/resources';
|
|
|
245
245
|
import { defineNotificationType, field } from '@diagonal-hq/cli';
|
|
246
246
|
|
|
247
247
|
export default defineNotificationType({
|
|
248
|
-
uid: '
|
|
248
|
+
uid: '019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e',
|
|
249
249
|
key: 'member-welcome',
|
|
250
250
|
name: 'Member welcome',
|
|
251
251
|
recipient: { resource: Resources.Members.slug },
|
|
@@ -263,7 +263,7 @@ A template has an email, an SMS, or both. A channel is on when the template has
|
|
|
263
263
|
import { defineNotificationTemplate } from '@diagonal-hq/cli';
|
|
264
264
|
|
|
265
265
|
export default defineNotificationTemplate({
|
|
266
|
-
uid: '
|
|
266
|
+
uid: '019a4d6e-4a1b-7c2d-8e3f-6a7b8c9d0e1f',
|
|
267
267
|
key: 'standard',
|
|
268
268
|
type: 'member-welcome',
|
|
269
269
|
name: 'Standard welcome',
|
|
@@ -292,7 +292,7 @@ An email layout is the frame that templates fill in. Each field is a slot that a
|
|
|
292
292
|
import { defineEmailLayout } from '@diagonal-hq/cli';
|
|
293
293
|
|
|
294
294
|
export default defineEmailLayout({
|
|
295
|
-
uid: '
|
|
295
|
+
uid: '019a4d6e-5b2c-7d3e-9f4a-7b8c9d0e1f2a',
|
|
296
296
|
key: 'standard',
|
|
297
297
|
name: 'Standard',
|
|
298
298
|
body: { file: './body.liquid' },
|
|
@@ -371,6 +371,7 @@ There is one `field.<type>` builder for each resource field type, in camel case:
|
|
|
371
371
|
|
|
372
372
|
A builder takes these options:
|
|
373
373
|
|
|
374
|
+
- `uid`: the stable identity of the field, unique in its resource. `diagonal check` writes a missing one. See [Definition uids and slugs](#definition-uids-and-slugs). The deploy stores it on the field, but the stored field id still derives from the resource and the field key, so a renamed key is still a new field.
|
|
374
375
|
- `label`, `description`, `required`, `default`, `unique`, and `index`.
|
|
375
376
|
- `guard`: more validation rules, for example `['max:255']`. Use `required` for the `required` and `nullable` rules.
|
|
376
377
|
- `settings`: the settings of the field type, with their stored names, and `settings.ui` for the record form. The seeder settings `seed_type`, `faker_method`, `faker_parameters`, and `seed_data` apply to every type.
|
|
@@ -378,7 +379,7 @@ A builder takes these options:
|
|
|
378
379
|
- `getter`: a resolver tree that transforms the stored value when it is read.
|
|
379
380
|
- `setter`: a resolver tree that computes the stored value before each create and update. `setterWhenEmpty: true` runs it only when the value is null or empty.
|
|
380
381
|
|
|
381
|
-
`field.select` takes `options` and `field.relation` takes `resource` (`Resources.<Name>.slug`) and `type` as options. Other settings go in `settings`. A setting that an option writes, such as `settings.unique`, is refused. A relation can declare `settings.inverse: { key, label?, settings? }`. The build then adds the inverse relation field to the target resource. A target that declares a field with the same key is an error.
|
|
382
|
+
`field.select` takes `options` and `field.relation` takes `resource` (`Resources.<Name>.slug`) and `type` as options. Other settings go in `settings`. A setting that an option writes, such as `settings.unique`, is refused. A relation can declare `settings.inverse: { uid, key, label?, settings? }`. `uid` is the uid of the inverse field. The build then adds the inverse relation field to the target resource. A target that declares a field with the same key is an error.
|
|
382
383
|
|
|
383
384
|
The platform deploy validates every field again with the rules of the resource builder, so a value that the build cannot check, such as an unknown guard rule, fails the deploy with the file path.
|
|
384
385
|
|
package/dist/cli.mjs
CHANGED
|
@@ -24430,7 +24430,7 @@ ${lanes.join("\n")}
|
|
|
24430
24430
|
initial
|
|
24431
24431
|
);
|
|
24432
24432
|
}
|
|
24433
|
-
function appendCommentRange(pos, end, kind, hasTrailingNewLine,
|
|
24433
|
+
function appendCommentRange(pos, end, kind, hasTrailingNewLine, _state2, comments = []) {
|
|
24434
24434
|
comments.push({ kind, pos, end, hasTrailingNewLine });
|
|
24435
24435
|
return comments;
|
|
24436
24436
|
}
|
|
@@ -144188,7 +144188,7 @@ ${lanes.join("\n")}
|
|
|
144188
144188
|
function onLeft(next, _workArea, parent2) {
|
|
144189
144189
|
return maybeEmitExpression(next, parent2, "left");
|
|
144190
144190
|
}
|
|
144191
|
-
function onOperator(operatorToken,
|
|
144191
|
+
function onOperator(operatorToken, _state2, node) {
|
|
144192
144192
|
const isCommaOperator = operatorToken.kind !== 28;
|
|
144193
144193
|
const linesBeforeOperator = getLinesBetweenNodes(node, node.left, operatorToken);
|
|
144194
144194
|
const linesAfterOperator = getLinesBetweenNodes(node, operatorToken, node.right);
|
|
@@ -224525,8 +224525,8 @@ var require_base = __commonJS({
|
|
|
224525
224525
|
function _interopRequireDefault(obj) {
|
|
224526
224526
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
224527
224527
|
}
|
|
224528
|
-
var
|
|
224529
|
-
var
|
|
224528
|
+
var _state2 = require_state();
|
|
224529
|
+
var _state22 = _interopRequireDefault(_state2);
|
|
224530
224530
|
var _charcodes = require_charcodes();
|
|
224531
224531
|
exports.isJSXEnabled;
|
|
224532
224532
|
exports.isTypeScriptEnabled;
|
|
@@ -224570,7 +224570,7 @@ var require_base = __commonJS({
|
|
|
224570
224570
|
exports.locationForIndex = locationForIndex;
|
|
224571
224571
|
function initParser(inputCode, isJSXEnabledArg, isTypeScriptEnabledArg, isFlowEnabledArg) {
|
|
224572
224572
|
exports.input = inputCode;
|
|
224573
|
-
exports.state = new (0,
|
|
224573
|
+
exports.state = new (0, _state22.default)();
|
|
224574
224574
|
exports.nextContextId = 1;
|
|
224575
224575
|
exports.isJSXEnabled = isJSXEnabledArg;
|
|
224576
224576
|
exports.isTypeScriptEnabled = isTypeScriptEnabledArg;
|
|
@@ -241101,7 +241101,7 @@ var require_expression = __commonJS({
|
|
|
241101
241101
|
var _typescript = require_typescript2();
|
|
241102
241102
|
var _index3 = require_tokenizer();
|
|
241103
241103
|
var _keywords = require_keywords();
|
|
241104
|
-
var
|
|
241104
|
+
var _state2 = require_state();
|
|
241105
241105
|
var _types3 = require_types();
|
|
241106
241106
|
var _charcodes = require_charcodes();
|
|
241107
241107
|
var _identifier = require_identifier();
|
|
@@ -241754,14 +241754,14 @@ var require_expression = __commonJS({
|
|
|
241754
241754
|
_statement.parseFunctionParams.call(void 0, allowModifiers, funcContextId);
|
|
241755
241755
|
parseFunctionBodyAndFinish(functionStart, funcContextId);
|
|
241756
241756
|
const endTokenIndex = _base.state.tokens.length;
|
|
241757
|
-
_base.state.scopes.push(new (0,
|
|
241757
|
+
_base.state.scopes.push(new (0, _state2.Scope)(startTokenIndex, endTokenIndex, true));
|
|
241758
241758
|
_base.state.scopeDepth--;
|
|
241759
241759
|
}
|
|
241760
241760
|
exports.parseMethod = parseMethod;
|
|
241761
241761
|
function parseArrowExpression(startTokenIndex) {
|
|
241762
241762
|
parseFunctionBody(true);
|
|
241763
241763
|
const endTokenIndex = _base.state.tokens.length;
|
|
241764
|
-
_base.state.scopes.push(new (0,
|
|
241764
|
+
_base.state.scopes.push(new (0, _state2.Scope)(startTokenIndex, endTokenIndex, true));
|
|
241765
241765
|
_base.state.scopeDepth--;
|
|
241766
241766
|
}
|
|
241767
241767
|
exports.parseArrowExpression = parseArrowExpression;
|
|
@@ -242725,7 +242725,7 @@ var require_statement = __commonJS({
|
|
|
242725
242725
|
var _typescript = require_typescript2();
|
|
242726
242726
|
var _tokenizer = require_tokenizer();
|
|
242727
242727
|
var _keywords = require_keywords();
|
|
242728
|
-
var
|
|
242728
|
+
var _state2 = require_state();
|
|
242729
242729
|
var _types = require_types();
|
|
242730
242730
|
var _charcodes = require_charcodes();
|
|
242731
242731
|
var _base = require_base();
|
|
@@ -242734,7 +242734,7 @@ var require_statement = __commonJS({
|
|
|
242734
242734
|
var _util = require_util();
|
|
242735
242735
|
function parseTopLevel() {
|
|
242736
242736
|
parseBlockBody(_types.TokenType.eof);
|
|
242737
|
-
_base.state.scopes.push(new (0,
|
|
242737
|
+
_base.state.scopes.push(new (0, _state2.Scope)(0, _base.state.tokens.length, true));
|
|
242738
242738
|
if (_base.state.scopeDepth !== 0) {
|
|
242739
242739
|
throw new Error(`Invalid scope depth at end of file: ${_base.state.scopeDepth}`);
|
|
242740
242740
|
}
|
|
@@ -242945,7 +242945,7 @@ var require_statement = __commonJS({
|
|
|
242945
242945
|
const startTokenIndex = _base.state.tokens.length;
|
|
242946
242946
|
parseAmbiguousForStatement();
|
|
242947
242947
|
const endTokenIndex = _base.state.tokens.length;
|
|
242948
|
-
_base.state.scopes.push(new (0,
|
|
242948
|
+
_base.state.scopes.push(new (0, _state2.Scope)(startTokenIndex, endTokenIndex, false));
|
|
242949
242949
|
_base.state.scopeDepth--;
|
|
242950
242950
|
}
|
|
242951
242951
|
function isUsingInLoop() {
|
|
@@ -243036,7 +243036,7 @@ var require_statement = __commonJS({
|
|
|
243036
243036
|
}
|
|
243037
243037
|
_tokenizer.next.call(void 0);
|
|
243038
243038
|
const endTokenIndex = _base.state.tokens.length;
|
|
243039
|
-
_base.state.scopes.push(new (0,
|
|
243039
|
+
_base.state.scopes.push(new (0, _state2.Scope)(startTokenIndex, endTokenIndex, false));
|
|
243040
243040
|
_base.state.scopeDepth--;
|
|
243041
243041
|
}
|
|
243042
243042
|
function parseThrowStatement() {
|
|
@@ -243070,7 +243070,7 @@ var require_statement = __commonJS({
|
|
|
243070
243070
|
parseBlock();
|
|
243071
243071
|
if (catchBindingStartTokenIndex != null) {
|
|
243072
243072
|
const endTokenIndex = _base.state.tokens.length;
|
|
243073
|
-
_base.state.scopes.push(new (0,
|
|
243073
|
+
_base.state.scopes.push(new (0, _state2.Scope)(catchBindingStartTokenIndex, endTokenIndex, false));
|
|
243074
243074
|
_base.state.scopeDepth--;
|
|
243075
243075
|
}
|
|
243076
243076
|
}
|
|
@@ -243116,7 +243116,7 @@ var require_statement = __commonJS({
|
|
|
243116
243116
|
_base.state.tokens[_base.state.tokens.length - 1].contextId = contextId;
|
|
243117
243117
|
}
|
|
243118
243118
|
const endTokenIndex = _base.state.tokens.length;
|
|
243119
|
-
_base.state.scopes.push(new (0,
|
|
243119
|
+
_base.state.scopes.push(new (0, _state2.Scope)(startTokenIndex, endTokenIndex, isFunctionScope));
|
|
243120
243120
|
_base.state.scopeDepth--;
|
|
243121
243121
|
}
|
|
243122
243122
|
exports.parseBlock = parseBlock;
|
|
@@ -243189,10 +243189,10 @@ var require_statement = __commonJS({
|
|
|
243189
243189
|
parseFunctionParams();
|
|
243190
243190
|
_expression.parseFunctionBodyAndFinish.call(void 0, functionStart);
|
|
243191
243191
|
const endTokenIndex = _base.state.tokens.length;
|
|
243192
|
-
_base.state.scopes.push(new (0,
|
|
243192
|
+
_base.state.scopes.push(new (0, _state2.Scope)(startTokenIndex, endTokenIndex, true));
|
|
243193
243193
|
_base.state.scopeDepth--;
|
|
243194
243194
|
if (nameScopeStartTokenIndex !== null) {
|
|
243195
|
-
_base.state.scopes.push(new (0,
|
|
243195
|
+
_base.state.scopes.push(new (0, _state2.Scope)(nameScopeStartTokenIndex, endTokenIndex, true));
|
|
243196
243196
|
_base.state.scopeDepth--;
|
|
243197
243197
|
}
|
|
243198
243198
|
}
|
|
@@ -243241,7 +243241,7 @@ var require_statement = __commonJS({
|
|
|
243241
243241
|
_base.state.tokens[_base.state.tokens.length - 1].contextId = contextId;
|
|
243242
243242
|
if (nameScopeStartTokenIndex !== null) {
|
|
243243
243243
|
const endTokenIndex = _base.state.tokens.length;
|
|
243244
|
-
_base.state.scopes.push(new (0,
|
|
243244
|
+
_base.state.scopes.push(new (0, _state2.Scope)(nameScopeStartTokenIndex, endTokenIndex, false));
|
|
243245
243245
|
_base.state.scopeDepth--;
|
|
243246
243246
|
}
|
|
243247
243247
|
}
|
|
@@ -268083,17 +268083,104 @@ function checkCapabilities(resources, platformSlugs, diagnostics) {
|
|
|
268083
268083
|
|
|
268084
268084
|
// scripts/lib/runtime-build/definition-uid.mjs
|
|
268085
268085
|
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
268086
|
-
var import_yaml = __toESM(require_dist(), 1);
|
|
268087
|
-
import { randomUUID } from "node:crypto";
|
|
268088
268086
|
import { writeFileSync as writeFileSync2 } from "node:fs";
|
|
268089
268087
|
import { join as join3 } from "node:path";
|
|
268088
|
+
|
|
268089
|
+
// node_modules/uuid/dist-node/index.js
|
|
268090
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
268091
|
+
|
|
268092
|
+
// node_modules/uuid/dist-node/stringify.js
|
|
268093
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
268094
|
+
var byteToHex = [];
|
|
268095
|
+
for (let i = 0; i < 256; ++i) {
|
|
268096
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
268097
|
+
}
|
|
268098
|
+
function unsafeStringify(arr, offset = 0) {
|
|
268099
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
268100
|
+
}
|
|
268101
|
+
|
|
268102
|
+
// node_modules/uuid/dist-node/rng.js
|
|
268103
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
268104
|
+
var rnds8 = new Uint8Array(16);
|
|
268105
|
+
function rng() {
|
|
268106
|
+
return crypto.getRandomValues(rnds8);
|
|
268107
|
+
}
|
|
268108
|
+
|
|
268109
|
+
// node_modules/uuid/dist-node/v7.js
|
|
268110
|
+
init_define_globalThis_DIAGONAL_SDK_RUNTIME();
|
|
268111
|
+
var _state = {};
|
|
268112
|
+
function v7(options2, buf, offset) {
|
|
268113
|
+
let bytes;
|
|
268114
|
+
if (options2) {
|
|
268115
|
+
bytes = v7Bytes(options2.random ?? options2.rng?.() ?? rng(), options2.msecs, options2.seq, buf, offset);
|
|
268116
|
+
} else {
|
|
268117
|
+
const now = Date.now();
|
|
268118
|
+
const rnds = rng();
|
|
268119
|
+
updateV7State(_state, now, rnds);
|
|
268120
|
+
bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset);
|
|
268121
|
+
}
|
|
268122
|
+
return buf ?? unsafeStringify(bytes);
|
|
268123
|
+
}
|
|
268124
|
+
function updateV7State(state, now, rnds) {
|
|
268125
|
+
state.msecs ??= -Infinity;
|
|
268126
|
+
state.seq ??= 0;
|
|
268127
|
+
if (now > state.msecs) {
|
|
268128
|
+
state.seq = v7Sequence(rnds);
|
|
268129
|
+
state.msecs = now;
|
|
268130
|
+
} else {
|
|
268131
|
+
state.seq = state.seq + 1 | 0;
|
|
268132
|
+
if (state.seq === 0) {
|
|
268133
|
+
state.msecs++;
|
|
268134
|
+
}
|
|
268135
|
+
}
|
|
268136
|
+
return state;
|
|
268137
|
+
}
|
|
268138
|
+
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
|
268139
|
+
if (rnds.length < 16) {
|
|
268140
|
+
throw new Error("Random bytes length must be >= 16");
|
|
268141
|
+
}
|
|
268142
|
+
if (!buf) {
|
|
268143
|
+
buf = new Uint8Array(16);
|
|
268144
|
+
offset = 0;
|
|
268145
|
+
} else {
|
|
268146
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
268147
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
268148
|
+
}
|
|
268149
|
+
}
|
|
268150
|
+
msecs ??= Date.now();
|
|
268151
|
+
seq ??= v7Sequence(rnds);
|
|
268152
|
+
buf[offset++] = msecs / 1099511627776 & 255;
|
|
268153
|
+
buf[offset++] = msecs / 4294967296 & 255;
|
|
268154
|
+
buf[offset++] = msecs / 16777216 & 255;
|
|
268155
|
+
buf[offset++] = msecs / 65536 & 255;
|
|
268156
|
+
buf[offset++] = msecs / 256 & 255;
|
|
268157
|
+
buf[offset++] = msecs & 255;
|
|
268158
|
+
buf[offset++] = 112 | seq >>> 28 & 15;
|
|
268159
|
+
buf[offset++] = seq >>> 20 & 255;
|
|
268160
|
+
buf[offset++] = 128 | seq >>> 14 & 63;
|
|
268161
|
+
buf[offset++] = seq >>> 6 & 255;
|
|
268162
|
+
buf[offset++] = seq << 2 & 255 | rnds[10] & 3;
|
|
268163
|
+
buf[offset++] = rnds[11];
|
|
268164
|
+
buf[offset++] = rnds[12];
|
|
268165
|
+
buf[offset++] = rnds[13];
|
|
268166
|
+
buf[offset++] = rnds[14];
|
|
268167
|
+
buf[offset++] = rnds[15];
|
|
268168
|
+
return buf;
|
|
268169
|
+
}
|
|
268170
|
+
function v7Sequence(rnds) {
|
|
268171
|
+
return (rnds[6] & 127) << 24 | rnds[7] << 16 | rnds[8] << 8 | rnds[9];
|
|
268172
|
+
}
|
|
268173
|
+
var v7_default = v7;
|
|
268174
|
+
|
|
268175
|
+
// scripts/lib/runtime-build/definition-uid.mjs
|
|
268176
|
+
var import_yaml = __toESM(require_dist(), 1);
|
|
268090
268177
|
var UID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
268091
|
-
var UID_EXAMPLE = "
|
|
268178
|
+
var UID_EXAMPLE = "019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e";
|
|
268092
268179
|
function isUid(value) {
|
|
268093
268180
|
return typeof value === "string" && UID_PATTERN.test(value);
|
|
268094
268181
|
}
|
|
268095
268182
|
function newUid() {
|
|
268096
|
-
return
|
|
268183
|
+
return v7_default();
|
|
268097
268184
|
}
|
|
268098
268185
|
function uidProperty(object) {
|
|
268099
268186
|
return object.properties.find(
|
|
@@ -268138,11 +268225,20 @@ function readDefinitionUid(definition) {
|
|
|
268138
268225
|
if (definition.frontMatter !== void 0) {
|
|
268139
268226
|
return readFrontMatterUid(definition.source, definition.frontMatter);
|
|
268140
268227
|
}
|
|
268228
|
+
if (isCallWithoutArguments(definition.node)) {
|
|
268229
|
+
return { uid: null, at: definition.node };
|
|
268230
|
+
}
|
|
268141
268231
|
const uid2 = readUid(definition.node);
|
|
268142
268232
|
return { uid: uid2, at: uid2 === null ? definition.node : uidProperty(definition.node).value };
|
|
268143
268233
|
}
|
|
268234
|
+
function isCallWithoutArguments(node) {
|
|
268235
|
+
return node.type === "CallExpression" && node.arguments.length === 0;
|
|
268236
|
+
}
|
|
268144
268237
|
function uidInsertion(source, object, uid2) {
|
|
268145
268238
|
const property = `uid: '${uid2}'`;
|
|
268239
|
+
if (isCallWithoutArguments(object)) {
|
|
268240
|
+
return { start: object.end - 1, end: object.end - 1, text: `{ ${property} }` };
|
|
268241
|
+
}
|
|
268146
268242
|
const [first] = object.properties;
|
|
268147
268243
|
const anchor = first === void 0 ? object.innerComments?.[0] : first.leadingComments?.[0] ?? first;
|
|
268148
268244
|
if (anchor === void 0) {
|
|
@@ -268209,7 +268305,7 @@ function planDefinitionUids(definitions, { write }) {
|
|
|
268209
268305
|
continue;
|
|
268210
268306
|
}
|
|
268211
268307
|
if (uid2 !== null) {
|
|
268212
|
-
const key = `${definition.type}\0${uid2}`;
|
|
268308
|
+
const key = `${definition.type}\0${definition.scope ?? ""}\0${uid2}`;
|
|
268213
268309
|
const first = firstByUid.get(key);
|
|
268214
268310
|
if (first === void 0) {
|
|
268215
268311
|
firstByUid.set(key, definition);
|
|
@@ -299060,6 +299156,7 @@ var field_catalog_default = {
|
|
|
299060
299156
|
var FIELD_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
299061
299157
|
var FIELD_CATALOG = field_catalog_default;
|
|
299062
299158
|
var FIELD_OPTIONS = /* @__PURE__ */ new Set([
|
|
299159
|
+
"uid",
|
|
299063
299160
|
"label",
|
|
299064
299161
|
"description",
|
|
299065
299162
|
"required",
|
|
@@ -299084,7 +299181,7 @@ var OPTION_FOR_SETTING = {
|
|
|
299084
299181
|
var NULLABILITY_RULES = /* @__PURE__ */ new Set(["required", "nullable"]);
|
|
299085
299182
|
var COMPUTED_CONFLICTS = ["default", "getter", "setter", "setterWhenEmpty", "unique", "index"];
|
|
299086
299183
|
var DERIVED_INVERSE_SETTINGS = /* @__PURE__ */ new Set(["resource_id", "type", "inverse"]);
|
|
299087
|
-
var INVERSE_KEYS = /* @__PURE__ */ new Set(["key", "label", "description", "settings"]);
|
|
299184
|
+
var INVERSE_KEYS = /* @__PURE__ */ new Set(["uid", "key", "label", "description", "settings"]);
|
|
299088
299185
|
var OPTION_KEYS = /* @__PURE__ */ new Set(["label", "value", "color"]);
|
|
299089
299186
|
function optionNode(builder2, ...path) {
|
|
299090
299187
|
let node = builder2.node.arguments?.[0] ?? builder2.node;
|
|
@@ -300128,7 +300225,7 @@ var PROPERTIES = {
|
|
|
300128
300225
|
manualOnly: { type: "boolean", required: false, fallback: false }
|
|
300129
300226
|
};
|
|
300130
300227
|
var KEYS = ["uid", ...Object.keys(PROPERTIES)];
|
|
300131
|
-
var EXAMPLE = ["---", "uid:
|
|
300228
|
+
var EXAMPLE = ["---", "uid: 019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e", "name: membership-support", "description: Help members with membership questions.", "---"].join("\n");
|
|
300132
300229
|
function characterCount(value) {
|
|
300133
300230
|
return [...value].length;
|
|
300134
300231
|
}
|
|
@@ -303649,12 +303746,97 @@ function pageKeyOfSource(path, source) {
|
|
|
303649
303746
|
throw error;
|
|
303650
303747
|
}
|
|
303651
303748
|
}
|
|
303652
|
-
function
|
|
303749
|
+
function objectProperty2(object, key) {
|
|
303750
|
+
return object.properties.find(
|
|
303751
|
+
(property) => property.type === "ObjectProperty" && propertyKey(property) === key
|
|
303752
|
+
) ?? null;
|
|
303753
|
+
}
|
|
303754
|
+
function withoutTypeAssertions(node) {
|
|
303755
|
+
let current = node;
|
|
303756
|
+
while (current?.type === "TSAsExpression" || current?.type === "TSSatisfiesExpression") {
|
|
303757
|
+
current = current.expression;
|
|
303758
|
+
}
|
|
303759
|
+
return current;
|
|
303760
|
+
}
|
|
303761
|
+
function fieldUidNodes(definition) {
|
|
303762
|
+
const fields = withoutTypeAssertions(objectProperty2(definition, "fields")?.value);
|
|
303763
|
+
if (fields?.type !== "ObjectExpression") {
|
|
303764
|
+
return [];
|
|
303765
|
+
}
|
|
303766
|
+
const nodes = [];
|
|
303767
|
+
for (const property of fields.properties) {
|
|
303768
|
+
if (property.type !== "ObjectProperty") {
|
|
303769
|
+
continue;
|
|
303770
|
+
}
|
|
303771
|
+
const call = withoutTypeAssertions(property.value);
|
|
303772
|
+
if (call.type !== "CallExpression") {
|
|
303773
|
+
continue;
|
|
303774
|
+
}
|
|
303775
|
+
const field2 = propertyKey(property);
|
|
303776
|
+
const [argument] = call.arguments;
|
|
303777
|
+
if (argument === void 0) {
|
|
303778
|
+
nodes.push({ type: "field", node: call, field: field2, inverse: false });
|
|
303779
|
+
continue;
|
|
303780
|
+
}
|
|
303781
|
+
const options2 = withoutTypeAssertions(argument);
|
|
303782
|
+
if (options2.type !== "ObjectExpression") {
|
|
303783
|
+
continue;
|
|
303784
|
+
}
|
|
303785
|
+
nodes.push({ type: "field", node: options2, field: field2, inverse: false });
|
|
303786
|
+
const settings = withoutTypeAssertions(objectProperty2(options2, "settings")?.value);
|
|
303787
|
+
const inverse = settings?.type === "ObjectExpression" ? withoutTypeAssertions(objectProperty2(settings, "inverse")?.value) : void 0;
|
|
303788
|
+
if (inverse?.type === "ObjectExpression") {
|
|
303789
|
+
nodes.push({ type: "field", node: inverse, field: field2, inverse: true });
|
|
303790
|
+
}
|
|
303791
|
+
}
|
|
303792
|
+
return nodes;
|
|
303793
|
+
}
|
|
303794
|
+
function fieldUidPosition(path, field2, inverse) {
|
|
303795
|
+
return `${path}\0${field2}\0${inverse ? "inverse" : "field"}`;
|
|
303796
|
+
}
|
|
303797
|
+
function checkInverseFieldUids(resources, pathsBySlug, diagnostics) {
|
|
303798
|
+
for (const resource of resources) {
|
|
303799
|
+
const firstByUid = /* @__PURE__ */ new Map();
|
|
303800
|
+
for (const field2 of resource.fields) {
|
|
303801
|
+
if (field2.uid === null) {
|
|
303802
|
+
continue;
|
|
303803
|
+
}
|
|
303804
|
+
const path = field2.inverse_of === void 0 ? resource.path : pathsBySlug.get(field2.inverse_of.resource);
|
|
303805
|
+
const first = firstByUid.get(field2.uid);
|
|
303806
|
+
if (first === void 0) {
|
|
303807
|
+
firstByUid.set(field2.uid, { field: field2, path });
|
|
303808
|
+
continue;
|
|
303809
|
+
}
|
|
303810
|
+
if (first.field.inverse_of === void 0 && field2.inverse_of === void 0) {
|
|
303811
|
+
continue;
|
|
303812
|
+
}
|
|
303813
|
+
diagnostics.push(
|
|
303814
|
+
diagnosticAt(
|
|
303815
|
+
path,
|
|
303816
|
+
null,
|
|
303817
|
+
`Duplicate field uid "${field2.uid}" on resource "${resource.slug}". Field "${first.field.key}" from ${first.path} and field "${field2.key}" from ${path} use it. Give one of them a new uid`
|
|
303818
|
+
)
|
|
303819
|
+
);
|
|
303820
|
+
}
|
|
303821
|
+
}
|
|
303822
|
+
}
|
|
303823
|
+
function uidDefinitionNodes(kind, path, ast) {
|
|
303653
303824
|
switch (kind) {
|
|
303654
303825
|
case "resource": {
|
|
303655
303826
|
const node = defineResourceArgument(ast);
|
|
303656
|
-
|
|
303657
|
-
|
|
303827
|
+
if (node.type !== "ObjectExpression") {
|
|
303828
|
+
return [{ type: "resource", node }];
|
|
303829
|
+
}
|
|
303830
|
+
if (objectProperty2(node, "platform") !== null) {
|
|
303831
|
+
return [];
|
|
303832
|
+
}
|
|
303833
|
+
return [
|
|
303834
|
+
{ type: "resource", node },
|
|
303835
|
+
...fieldUidNodes(node).map((field2) => ({
|
|
303836
|
+
...field2,
|
|
303837
|
+
scope: field2.inverse ? fieldUidPosition(path, field2.field, true) : path
|
|
303838
|
+
}))
|
|
303839
|
+
];
|
|
303658
303840
|
}
|
|
303659
303841
|
case "page": {
|
|
303660
303842
|
const { declaration } = defaultExportOf(ast, { helpers: "anywhere", allowAppImports: true });
|
|
@@ -303697,6 +303879,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303697
303879
|
const workflowFiles = [];
|
|
303698
303880
|
const uidDefinitions = [];
|
|
303699
303881
|
const uidPositions = /* @__PURE__ */ new Map();
|
|
303882
|
+
const fieldUidPositions = /* @__PURE__ */ new Map();
|
|
303700
303883
|
const migratedPages = /* @__PURE__ */ new Map();
|
|
303701
303884
|
const skillFiles = [];
|
|
303702
303885
|
const workflowTestFiles = [];
|
|
@@ -303761,8 +303944,13 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303761
303944
|
output.platform_resources.push(resource);
|
|
303762
303945
|
} else {
|
|
303763
303946
|
output.resources.push(resource);
|
|
303764
|
-
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
303765
|
-
|
|
303947
|
+
for (const { type, scope: scope2, node, field: field2, inverse } of uidDefinitionNodes(kind, path, ast)) {
|
|
303948
|
+
const position2 = uidDefinitions.push({ type, scope: scope2, path, source, node }) - 1;
|
|
303949
|
+
if (field2 === void 0) {
|
|
303950
|
+
uidPositions.set(path, position2);
|
|
303951
|
+
} else {
|
|
303952
|
+
fieldUidPositions.set(fieldUidPosition(path, field2, inverse), position2);
|
|
303953
|
+
}
|
|
303766
303954
|
}
|
|
303767
303955
|
}
|
|
303768
303956
|
diagnostics.push(...slugStringWarnings(path, definition, names2));
|
|
@@ -303776,7 +303964,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303776
303964
|
}
|
|
303777
303965
|
const page = buildPage(path, fixed, pageAst, root, resourcesBinding(pageAst, names2));
|
|
303778
303966
|
output.pages.push(page);
|
|
303779
|
-
for (const { type, node } of uidDefinitionNodes(kind, pageAst)) {
|
|
303967
|
+
for (const { type, node } of uidDefinitionNodes(kind, path, pageAst)) {
|
|
303780
303968
|
uidPositions.set(path, uidDefinitions.push({ type, path, source: fixed, node }) - 1);
|
|
303781
303969
|
}
|
|
303782
303970
|
diagnostics.push(
|
|
@@ -303796,7 +303984,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303796
303984
|
break;
|
|
303797
303985
|
case "workflow":
|
|
303798
303986
|
workflowFiles.push({ path, source, ast });
|
|
303799
|
-
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
303987
|
+
for (const { type, node } of uidDefinitionNodes(kind, path, ast)) {
|
|
303800
303988
|
uidPositions.set(path, uidDefinitions.push({ type, path, source, node }) - 1);
|
|
303801
303989
|
}
|
|
303802
303990
|
break;
|
|
@@ -303809,7 +303997,7 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303809
303997
|
case "notification_type":
|
|
303810
303998
|
case "notification_template":
|
|
303811
303999
|
case "email_layout":
|
|
303812
|
-
for (const { type, node } of uidDefinitionNodes(kind, ast)) {
|
|
304000
|
+
for (const { type, node } of uidDefinitionNodes(kind, path, ast)) {
|
|
303813
304001
|
uidDefinitions.push({ type, path, source, node });
|
|
303814
304002
|
}
|
|
303815
304003
|
break;
|
|
@@ -303854,9 +304042,15 @@ function buildWorkspace(root, { assetCatalog = null, writeSource = false, fixSou
|
|
|
303854
304042
|
writeFileSync4(join11(root, path), source);
|
|
303855
304043
|
}
|
|
303856
304044
|
}
|
|
304045
|
+
const pathsBySlug = new Map(output.resources.map((resource) => [resource.slug, resource.path]));
|
|
303857
304046
|
for (const resource of output.resources) {
|
|
303858
304047
|
resource.uid = uidCheck.uids[uidPositions.get(resource.path)];
|
|
304048
|
+
for (const field2 of resource.fields) {
|
|
304049
|
+
const position2 = field2.inverse_of === void 0 ? fieldUidPosition(resource.path, field2.key, false) : fieldUidPosition(pathsBySlug.get(field2.inverse_of.resource), field2.inverse_of.key, true);
|
|
304050
|
+
field2.uid = uidCheck.uids[fieldUidPositions.get(position2)] ?? null;
|
|
304051
|
+
}
|
|
303859
304052
|
}
|
|
304053
|
+
checkInverseFieldUids(output.resources, pathsBySlug, diagnostics);
|
|
303860
304054
|
for (const page of output.pages) {
|
|
303861
304055
|
page.uid = uidCheck.uids[uidPositions.get(page.path)];
|
|
303862
304056
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by `artisan app:generate-custom-typescript` from VariableType. Do not edit.
|
|
2
2
|
// The field builders of defineResource, one for each resource field type, the data API endpoints, the filter operators, and the record meta fields.
|
|
3
3
|
|
|
4
|
-
import type { StaticValue } from './index';
|
|
4
|
+
import type { DefinitionUid, StaticValue } from './index';
|
|
5
5
|
|
|
6
6
|
export type FieldType = "boolean" | "color" | "content" | "date" | "datetime" | "dictionary" | "email" | "event_schedule" | "file_reference" | "liquid" | "list" | "location" | "markdown" | "money" | "number" | "password" | "phone" | "recurrence" | "regular_hours" | "relation" | "resource_reference" | "select" | "text" | "time" | "timezone" | "url" | "uuid" | "wallet_accounting_account" | "wallet_accounting_entity";
|
|
7
7
|
|
|
@@ -43,6 +43,8 @@ export type FieldDefinition<TType extends FieldType = FieldType> = {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
type BaseFieldOptions<TSettings> = {
|
|
46
|
+
/** The uid of the field, unique in its resource. `diagonal check` writes a missing one. */
|
|
47
|
+
uid?: DefinitionUid;
|
|
46
48
|
label?: string;
|
|
47
49
|
description?: string | null;
|
|
48
50
|
/** Adds the `required` guard. Without it the field is nullable. */
|
|
@@ -371,6 +373,8 @@ export type WalletAccountingEntityFieldSettings = CommonFieldSettings & {
|
|
|
371
373
|
* and its relation type is the inverse of the declaring relation type.
|
|
372
374
|
*/
|
|
373
375
|
export type RelationInverse = {
|
|
376
|
+
/** The uid of the inverse field, unique in the target resource. `diagonal check` writes a missing one. */
|
|
377
|
+
uid?: DefinitionUid;
|
|
374
378
|
key: string;
|
|
375
379
|
label?: string;
|
|
376
380
|
description?: string | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export type StaticValue =
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* The stable identity of a definition: a lowercase UUID string literal, such as
|
|
42
|
-
* `'
|
|
42
|
+
* `'019a4d6e-3c2f-7b8a-9d1e-5f6a7b8c9d0e'`. `diagonal check` writes one into a
|
|
43
43
|
* definition that has none. A file move or a rename keeps it. Do not change it.
|
|
44
44
|
*/
|
|
45
45
|
export type DefinitionUid = string;
|