@peers-app/peers-sdk 0.14.0 → 0.15.0
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/context/data-context.d.ts +4 -4
- package/dist/context/data-context.js +1 -1
- package/dist/context/index.d.ts +3 -3
- package/dist/context/index.js +4 -0
- package/dist/context/user-context-singleton.js +13 -14
- package/dist/context/user-context.d.ts +4 -4
- package/dist/context/user-context.js +48 -31
- package/dist/data/assistants.d.ts +1 -1
- package/dist/data/assistants.js +35 -24
- package/dist/data/change-tracking.d.ts +8 -8
- package/dist/data/change-tracking.js +45 -39
- package/dist/data/channels.js +5 -5
- package/dist/data/data-locks.d.ts +2 -2
- package/dist/data/data-locks.js +21 -23
- package/dist/data/data-locks.test.js +73 -75
- package/dist/data/device-sync-info.d.ts +1 -1
- package/dist/data/device-sync-info.js +4 -4
- package/dist/data/devices.d.ts +1 -1
- package/dist/data/devices.js +9 -12
- package/dist/data/embeddings.js +14 -11
- package/dist/data/files/file-read-stream.d.ts +2 -2
- package/dist/data/files/file-read-stream.js +23 -14
- package/dist/data/files/file-write-stream.d.ts +2 -2
- package/dist/data/files/file-write-stream.js +8 -8
- package/dist/data/files/file.types.d.ts +2 -2
- package/dist/data/files/file.types.js +17 -11
- package/dist/data/files/files.d.ts +6 -6
- package/dist/data/files/files.js +17 -19
- package/dist/data/files/files.test.js +213 -214
- package/dist/data/files/index.d.ts +4 -4
- package/dist/data/files/index.js +4 -4
- package/dist/data/group-member-roles.js +2 -2
- package/dist/data/group-members.d.ts +5 -5
- package/dist/data/group-members.js +27 -18
- package/dist/data/group-members.test.js +73 -73
- package/dist/data/group-permissions.d.ts +3 -3
- package/dist/data/group-permissions.js +13 -11
- package/dist/data/group-share.d.ts +2 -2
- package/dist/data/group-share.js +29 -24
- package/dist/data/groups.d.ts +4 -4
- package/dist/data/groups.js +27 -19
- package/dist/data/groups.test.js +44 -44
- package/dist/data/index.d.ts +6 -6
- package/dist/data/index.js +6 -6
- package/dist/data/knowledge/peer-types.js +9 -9
- package/dist/data/messages.d.ts +5 -5
- package/dist/data/messages.js +43 -30
- package/dist/data/orm/client-proxy.data-source.d.ts +4 -4
- package/dist/data/orm/client-proxy.data-source.js +10 -12
- package/dist/data/orm/cursor.d.ts +1 -1
- package/dist/data/orm/cursor.js +2 -2
- package/dist/data/orm/cursor.test.js +92 -93
- package/dist/data/orm/data-query.d.ts +3 -3
- package/dist/data/orm/data-query.js +24 -18
- package/dist/data/orm/data-query.mongo.d.ts +1 -1
- package/dist/data/orm/data-query.mongo.js +49 -51
- package/dist/data/orm/data-query.mongo.test.js +173 -204
- package/dist/data/orm/data-query.sqlite.d.ts +1 -1
- package/dist/data/orm/data-query.sqlite.js +84 -73
- package/dist/data/orm/data-query.sqlite.test.js +164 -176
- package/dist/data/orm/data-query.test.js +216 -224
- package/dist/data/orm/decorators.js +3 -3
- package/dist/data/orm/dependency-injection.test.js +53 -56
- package/dist/data/orm/doc.d.ts +4 -4
- package/dist/data/orm/doc.js +17 -21
- package/dist/data/orm/event-registry.d.ts +1 -1
- package/dist/data/orm/event-registry.test.js +16 -16
- package/dist/data/orm/factory.d.ts +2 -2
- package/dist/data/orm/factory.js +33 -33
- package/dist/data/orm/index.d.ts +10 -10
- package/dist/data/orm/index.js +10 -10
- package/dist/data/orm/multi-cursors.d.ts +1 -1
- package/dist/data/orm/multi-cursors.js +6 -6
- package/dist/data/orm/multi-cursors.test.js +152 -144
- package/dist/data/orm/sql.data-source.d.ts +7 -7
- package/dist/data/orm/sql.data-source.js +88 -93
- package/dist/data/orm/sql.data-source.test.js +109 -101
- package/dist/data/orm/subscribable.data-source.d.ts +4 -4
- package/dist/data/orm/subscribable.data-source.js +5 -5
- package/dist/data/orm/table-container-events.test.js +34 -26
- package/dist/data/orm/table-container.d.ts +6 -6
- package/dist/data/orm/table-container.js +33 -21
- package/dist/data/orm/table-container.test.js +64 -53
- package/dist/data/orm/table-definitions.system.d.ts +3 -3
- package/dist/data/orm/table-definitions.system.js +3 -3
- package/dist/data/orm/table-definitions.type.d.ts +5 -5
- package/dist/data/orm/table-dependencies.d.ts +2 -2
- package/dist/data/orm/table.d.ts +5 -5
- package/dist/data/orm/table.event-source.test.js +105 -115
- package/dist/data/orm/table.js +35 -34
- package/dist/data/orm/types.d.ts +3 -3
- package/dist/data/orm/types.js +26 -25
- package/dist/data/orm/types.test.js +166 -92
- package/dist/data/package-permissions.d.ts +1 -1
- package/dist/data/package-permissions.js +2 -2
- package/dist/data/package-version-permissions.d.ts +1 -1
- package/dist/data/package-version-permissions.js +2 -2
- package/dist/data/package-versions.d.ts +9 -9
- package/dist/data/package-versions.js +47 -33
- package/dist/data/packages.d.ts +2 -2
- package/dist/data/packages.js +36 -18
- package/dist/data/packages.utils.d.ts +2 -2
- package/dist/data/packages.utils.js +4 -4
- package/dist/data/persistent-vars.d.ts +15 -15
- package/dist/data/persistent-vars.js +165 -154
- package/dist/data/table-definitions-table.d.ts +5 -5
- package/dist/data/table-definitions-table.js +13 -12
- package/dist/data/tool-tests.js +6 -6
- package/dist/data/tools.js +29 -19
- package/dist/data/user-permissions.d.ts +1 -1
- package/dist/data/user-permissions.js +5 -5
- package/dist/data/user-permissions.test.js +90 -88
- package/dist/data/user-trust-levels.js +10 -10
- package/dist/data/users.d.ts +4 -4
- package/dist/data/users.js +16 -15
- package/dist/data/voice-messages.d.ts +2 -2
- package/dist/data/voice-messages.js +13 -13
- package/dist/data/welcome-modal.pvar.js +3 -1
- package/dist/data/workflow-logs.js +26 -18
- package/dist/data/workflow-runs.d.ts +6 -6
- package/dist/data/workflow-runs.js +70 -44
- package/dist/data/workflows.d.ts +2 -2
- package/dist/data/workflows.js +7 -9
- package/dist/device/binary-peer-connection-v2.d.ts +7 -7
- package/dist/device/binary-peer-connection-v2.js +32 -28
- package/dist/device/binary-peer-connection-v2.test.js +80 -67
- package/dist/device/binary-peer-connection.d.ts +7 -7
- package/dist/device/binary-peer-connection.js +29 -28
- package/dist/device/binary-peer-connection.test.js +35 -31
- package/dist/device/connection.d.ts +5 -5
- package/dist/device/connection.js +59 -48
- package/dist/device/connection.test.js +74 -68
- package/dist/device/device-election.d.ts +2 -2
- package/dist/device/device-election.js +25 -20
- package/dist/device/device-election.test.js +35 -36
- package/dist/device/device.d.ts +2 -2
- package/dist/device/device.js +10 -4
- package/dist/device/device.test.js +16 -17
- package/dist/device/get-trust-level-fn.d.ts +2 -2
- package/dist/device/get-trust-level-fn.js +22 -11
- package/dist/device/get-trust-level-fn.test.js +58 -58
- package/dist/device/socket-io-binary-peer.d.ts +1 -1
- package/dist/device/socket-io-binary-peer.js +16 -13
- package/dist/device/socket.type.d.ts +2 -2
- package/dist/device/streamed-socket.d.ts +2 -2
- package/dist/device/streamed-socket.js +8 -8
- package/dist/device/streamed-socket.test.js +40 -40
- package/dist/device/tx-encoding.test.js +77 -77
- package/dist/events.d.ts +1 -1
- package/dist/events.js +5 -2
- package/dist/group-invite/group-invite.js +110 -19
- package/dist/group-invite/group-invite.pvars.d.ts +2 -2
- package/dist/group-invite/group-invite.pvars.js +21 -13
- package/dist/group-invite/group-invite.types.d.ts +1 -1
- package/dist/group-invite/index.d.ts +3 -3
- package/dist/group-invite/index.js +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +30 -25
- package/dist/keys.d.ts +3 -3
- package/dist/keys.js +31 -30
- package/dist/keys.test.js +69 -61
- package/dist/logging/console-logger.d.ts +1 -1
- package/dist/logging/console-logger.js +35 -40
- package/dist/logging/console-logger.test.js +115 -115
- package/dist/logging/console-logs.table.d.ts +3 -3
- package/dist/logging/console-logs.table.js +28 -23
- package/dist/mentions.js +16 -12
- package/dist/observable.d.ts +2 -2
- package/dist/observable.js +15 -9
- package/dist/observable.test.js +47 -47
- package/dist/package-loader/get-require.js +3 -4
- package/dist/package-loader/package-loader.d.ts +2 -2
- package/dist/package-loader/package-loader.js +52 -34
- package/dist/peers-ui/peers-ui.d.ts +2 -2
- package/dist/peers-ui/peers-ui.js +2 -4
- package/dist/peers-ui/peers-ui.types.d.ts +3 -3
- package/dist/peers-ui/peers-ui.types.js +0 -1
- package/dist/rpc-types.d.ts +61 -59
- package/dist/rpc-types.js +61 -55
- package/dist/serial-json.d.ts +1 -1
- package/dist/serial-json.js +50 -43
- package/dist/serial-json.test.js +22 -22
- package/dist/system-ids.js +8 -8
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/tools-factory.d.ts +1 -1
- package/dist/tools/tools-factory.js +2 -2
- package/dist/types/assistant-runner-args.d.ts +3 -3
- package/dist/types/peer-device.d.ts +1 -1
- package/dist/types/peers-package.d.ts +3 -3
- package/dist/types/workflow-logger.d.ts +1 -1
- package/dist/types/workflow-run-context.d.ts +4 -4
- package/dist/types/workflow.d.ts +4 -4
- package/dist/types/workflow.js +27 -14
- package/dist/types/zod-types.d.ts +2 -1
- package/dist/types/zod-types.js +9 -3
- package/dist/user-connect/connection-code.d.ts +1 -1
- package/dist/user-connect/connection-code.js +7 -7
- package/dist/user-connect/connection-code.test.js +106 -106
- package/dist/user-connect/index.d.ts +3 -3
- package/dist/user-connect/index.js +1 -1
- package/dist/user-connect/user-connect.pvars.js +13 -11
- package/dist/user-connect/user-connect.types.d.ts +3 -3
- package/dist/users.query.d.ts +2 -2
- package/dist/users.query.js +40 -30
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +34 -32
- package/dist/utils.test.js +12 -8
- package/dist/workflow-log-formatter.d.ts +1 -1
- package/dist/workflow-log-formatter.js +17 -18
- package/package.json +14 -8
package/dist/data/orm/types.js
CHANGED
|
@@ -11,23 +11,23 @@ function fieldsToSchema(fields, codeSchema) {
|
|
|
11
11
|
const { name, description, type, isArray, defaultValue, optional } = argSchema;
|
|
12
12
|
let propertyType;
|
|
13
13
|
switch (type) {
|
|
14
|
-
case
|
|
15
|
-
propertyType = zod_1.z.string().refine((id => (0, utils_1.isid)(id)
|
|
14
|
+
case "id":
|
|
15
|
+
propertyType = zod_1.z.string().refine((id) => (0, utils_1.isid)(id), { message: "Invalid id" });
|
|
16
16
|
propertyType._def._fieldType = field_type_1.FieldType.id;
|
|
17
17
|
break;
|
|
18
|
-
case
|
|
18
|
+
case "string":
|
|
19
19
|
propertyType = zod_1.z.string();
|
|
20
20
|
break;
|
|
21
|
-
case
|
|
21
|
+
case "number":
|
|
22
22
|
propertyType = zod_1.z.number();
|
|
23
23
|
break;
|
|
24
|
-
case
|
|
24
|
+
case "boolean":
|
|
25
25
|
propertyType = zod_1.z.boolean();
|
|
26
26
|
break;
|
|
27
|
-
case
|
|
27
|
+
case "Date":
|
|
28
28
|
propertyType = zod_1.z.date();
|
|
29
29
|
break;
|
|
30
|
-
case
|
|
30
|
+
case "object":
|
|
31
31
|
propertyType = zod_1.z.object({});
|
|
32
32
|
break;
|
|
33
33
|
default:
|
|
@@ -39,13 +39,13 @@ function fieldsToSchema(fields, codeSchema) {
|
|
|
39
39
|
if (optional) {
|
|
40
40
|
propertyType = propertyType.optional();
|
|
41
41
|
}
|
|
42
|
-
if (defaultValue) {
|
|
43
|
-
// @ts-ignore
|
|
42
|
+
if (defaultValue !== undefined) {
|
|
44
43
|
propertyType = propertyType.default(defaultValue);
|
|
45
44
|
}
|
|
46
|
-
propertyType = propertyType.describe(description);
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
propertyType = propertyType.describe(description ?? "");
|
|
46
|
+
const shapeField = codeSchema?.shape?.[name];
|
|
47
|
+
if (shapeField) {
|
|
48
|
+
propertyType = zod_1.z.intersection(propertyType, shapeField);
|
|
49
49
|
}
|
|
50
50
|
const newProperty = { [name]: propertyType };
|
|
51
51
|
argsSchema = argsSchema.extend(newProperty);
|
|
@@ -58,10 +58,10 @@ function schemaToFields(schema) {
|
|
|
58
58
|
const field = schema.shape[name];
|
|
59
59
|
let type = field_type_1.FieldType.any;
|
|
60
60
|
let _def = field._def;
|
|
61
|
-
let isArray
|
|
61
|
+
let isArray;
|
|
62
62
|
let brandedFieldType;
|
|
63
63
|
while (true) {
|
|
64
|
-
if (_def.typeName ===
|
|
64
|
+
if (_def.typeName === "ZodArray") {
|
|
65
65
|
isArray = true;
|
|
66
66
|
}
|
|
67
67
|
if (_def._fieldType) {
|
|
@@ -82,39 +82,40 @@ function schemaToFields(schema) {
|
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
84
84
|
switch (_def.typeName) {
|
|
85
|
-
case
|
|
85
|
+
case "ZodString":
|
|
86
86
|
type = brandedFieldType || field_type_1.FieldType.string;
|
|
87
87
|
break;
|
|
88
|
-
case
|
|
88
|
+
case "ZodNumber":
|
|
89
89
|
type = field_type_1.FieldType.number;
|
|
90
90
|
break;
|
|
91
|
-
case
|
|
91
|
+
case "ZodBoolean":
|
|
92
92
|
type = field_type_1.FieldType.boolean;
|
|
93
93
|
break;
|
|
94
|
-
case
|
|
94
|
+
case "ZodDate":
|
|
95
95
|
type = field_type_1.FieldType.Date;
|
|
96
96
|
break;
|
|
97
|
-
case
|
|
97
|
+
case "ZodObject":
|
|
98
98
|
type = field_type_1.FieldType.object;
|
|
99
99
|
break;
|
|
100
|
-
case
|
|
100
|
+
case "ZodNativeEnum": {
|
|
101
101
|
// number or string
|
|
102
|
-
const hasNumber = Object.values(_def.values).some(v => typeof v ===
|
|
102
|
+
const hasNumber = Object.values(_def.values).some((v) => typeof v === "number");
|
|
103
103
|
type = hasNumber ? field_type_1.FieldType.number : field_type_1.FieldType.string;
|
|
104
104
|
break;
|
|
105
|
+
}
|
|
105
106
|
default:
|
|
106
107
|
type = field_type_1.FieldType.any;
|
|
107
108
|
}
|
|
108
|
-
if (!isArray && field._def.typeName ===
|
|
109
|
+
if (!isArray && field._def.typeName === "ZodArray") {
|
|
109
110
|
isArray = true;
|
|
110
111
|
// isArray = field._def.typeName === 'ZodArray' || undefined;
|
|
111
112
|
}
|
|
112
|
-
const optional = field._def.typeName ===
|
|
113
|
+
const optional = field._def.typeName === "ZodOptional" || undefined;
|
|
113
114
|
const description = field._def.description;
|
|
114
115
|
const defaultValue = field._def.defaultValue;
|
|
115
116
|
const newField = { name, type, isArray, optional, description, defaultValue };
|
|
116
|
-
Object.keys(newField).forEach(k => {
|
|
117
|
-
// @ts-
|
|
117
|
+
Object.keys(newField).forEach((k) => {
|
|
118
|
+
// @ts-expect-error
|
|
118
119
|
if (newField[k] === undefined)
|
|
119
120
|
delete newField[k];
|
|
120
121
|
});
|
|
@@ -1,38 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const zod_1 = require("zod");
|
|
4
|
-
const types_1 = require("./types");
|
|
5
4
|
const field_type_1 = require("../../types/field-type");
|
|
6
|
-
const utils_1 = require("../../utils");
|
|
7
5
|
const zod_types_1 = require("../../types/zod-types");
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
describe("types", () => {
|
|
9
|
+
it("fieldsToSchema", () => {
|
|
10
10
|
const someDate = new Date();
|
|
11
11
|
const groupFields = [
|
|
12
|
-
{ name:
|
|
13
|
-
{ name:
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
{ name: "groupId", description: "The id of the group", type: field_type_1.FieldType.id },
|
|
13
|
+
{ name: "groupName", description: "The name of the group", type: field_type_1.FieldType.string },
|
|
14
|
+
{
|
|
15
|
+
name: "groupDescription",
|
|
16
|
+
description: "The description of the group",
|
|
17
|
+
type: field_type_1.FieldType.string,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "createdAt",
|
|
21
|
+
description: "The date the group was created",
|
|
22
|
+
type: field_type_1.FieldType.Date,
|
|
23
|
+
defaultValue: () => someDate,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "owningUserIds",
|
|
27
|
+
description: "The ids of the users who own the group",
|
|
28
|
+
type: field_type_1.FieldType.string,
|
|
29
|
+
isArray: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "isPublic",
|
|
33
|
+
description: "Whether the group is public or private",
|
|
34
|
+
type: field_type_1.FieldType.boolean,
|
|
35
|
+
optional: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "fileIds",
|
|
39
|
+
description: "The ids of files attached to this chat entry",
|
|
40
|
+
type: field_type_1.FieldType.string,
|
|
41
|
+
isArray: true,
|
|
42
|
+
optional: true,
|
|
43
|
+
},
|
|
19
44
|
];
|
|
20
45
|
const groupSchema = (0, types_1.fieldsToSchema)(groupFields);
|
|
21
46
|
const groupSchemaExpected = zod_1.z.object({
|
|
22
|
-
groupId: zod_1.z.string().describe(
|
|
23
|
-
groupName: zod_1.z.string().describe(
|
|
24
|
-
groupDescription: zod_1.z.string().describe(
|
|
25
|
-
createdAt: zod_1.z
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
groupId: zod_1.z.string().describe("The id of the group"),
|
|
48
|
+
groupName: zod_1.z.string().describe("The name of the group"),
|
|
49
|
+
groupDescription: zod_1.z.string().describe("The description of the group"),
|
|
50
|
+
createdAt: zod_1.z
|
|
51
|
+
.date()
|
|
52
|
+
.describe("The date the group was created")
|
|
53
|
+
.default(() => someDate),
|
|
54
|
+
owningUserIds: zod_1.z.string().array().describe("The ids of the users who own the group"),
|
|
55
|
+
isPublic: zod_1.z.boolean().optional().describe("Whether the group is public or private"),
|
|
56
|
+
fileIds: zod_1.z
|
|
57
|
+
.string()
|
|
58
|
+
.array()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe("The ids of files attached to this chat entry"),
|
|
29
61
|
});
|
|
30
62
|
const aGroup = {
|
|
31
63
|
groupId: (0, utils_1.newid)(),
|
|
32
|
-
groupName:
|
|
33
|
-
groupDescription:
|
|
64
|
+
groupName: "group",
|
|
65
|
+
groupDescription: "group description",
|
|
34
66
|
createdAt: new Date(),
|
|
35
|
-
owningUserIds: [
|
|
67
|
+
owningUserIds: ["1"],
|
|
36
68
|
isPublic: true,
|
|
37
69
|
};
|
|
38
70
|
const aGroup2 = { ...aGroup, createdAt: undefined };
|
|
@@ -42,104 +74,143 @@ describe('types', () => {
|
|
|
42
74
|
expect(r1e.createdAt).toEqual(someDate);
|
|
43
75
|
// @ts-expect-error
|
|
44
76
|
delete aGroup.groupId;
|
|
45
|
-
expect(() => groupSchema.parse(aGroup)).toThrow(
|
|
46
|
-
expect(() => groupSchemaExpected.parse(aGroup)).toThrow(
|
|
77
|
+
expect(() => groupSchema.parse(aGroup)).toThrow("groupId");
|
|
78
|
+
expect(() => groupSchemaExpected.parse(aGroup)).toThrow("groupId");
|
|
47
79
|
});
|
|
48
|
-
it(
|
|
80
|
+
it("schemaToFields", () => {
|
|
49
81
|
const groupSchema = zod_1.z.object({
|
|
50
|
-
groupId: zod_1.z.string().describe(
|
|
51
|
-
groupName: zod_1.z.string().describe(
|
|
52
|
-
groupDescription: zod_1.z.string().describe(
|
|
53
|
-
createdAt: zod_1.z.date().describe(
|
|
54
|
-
owningUserIds: zod_1.z.string().array().describe(
|
|
55
|
-
isPublic: zod_1.z.boolean().optional().describe(
|
|
56
|
-
instructionResults: zod_1.z
|
|
57
|
-
|
|
82
|
+
groupId: zod_1.z.string().describe("The id of the group"),
|
|
83
|
+
groupName: zod_1.z.string().describe("The name of the group"),
|
|
84
|
+
groupDescription: zod_1.z.string().describe("The description of the group"),
|
|
85
|
+
createdAt: zod_1.z.date().describe("The date the group was created"), //.default(() => new Date()),
|
|
86
|
+
owningUserIds: zod_1.z.string().array().describe("The ids of the users who own the group"),
|
|
87
|
+
isPublic: zod_1.z.boolean().optional().describe("Whether the group is public or private"),
|
|
88
|
+
instructionResults: zod_1.z
|
|
89
|
+
.any()
|
|
90
|
+
.array()
|
|
91
|
+
.describe("The results of the instructions that have been run."),
|
|
92
|
+
fileIds: zod_1.z
|
|
93
|
+
.string()
|
|
94
|
+
.array()
|
|
95
|
+
.optional()
|
|
96
|
+
.describe("The ids of files attached to this chat entry"),
|
|
58
97
|
});
|
|
59
98
|
const groupFields = (0, types_1.schemaToFields)(groupSchema);
|
|
60
99
|
const groupFieldsExpected = [
|
|
61
|
-
{ name:
|
|
62
|
-
{ name:
|
|
63
|
-
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
{ name:
|
|
100
|
+
{ name: "groupId", description: "The id of the group", type: field_type_1.FieldType.string },
|
|
101
|
+
{ name: "groupName", description: "The name of the group", type: field_type_1.FieldType.string },
|
|
102
|
+
{
|
|
103
|
+
name: "groupDescription",
|
|
104
|
+
description: "The description of the group",
|
|
105
|
+
type: field_type_1.FieldType.string,
|
|
106
|
+
},
|
|
107
|
+
{ name: "createdAt", description: "The date the group was created", type: field_type_1.FieldType.Date }, //defaultValue: () => new Date() },
|
|
108
|
+
{
|
|
109
|
+
name: "owningUserIds",
|
|
110
|
+
description: "The ids of the users who own the group",
|
|
111
|
+
type: field_type_1.FieldType.string,
|
|
112
|
+
isArray: true,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "isPublic",
|
|
116
|
+
description: "Whether the group is public or private",
|
|
117
|
+
type: field_type_1.FieldType.boolean,
|
|
118
|
+
optional: true,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "instructionResults",
|
|
122
|
+
description: "The results of the instructions that have been run.",
|
|
123
|
+
type: field_type_1.FieldType.any,
|
|
124
|
+
isArray: true,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "fileIds",
|
|
128
|
+
description: "The ids of files attached to this chat entry",
|
|
129
|
+
type: field_type_1.FieldType.string,
|
|
130
|
+
isArray: true,
|
|
131
|
+
optional: true,
|
|
132
|
+
},
|
|
69
133
|
];
|
|
70
134
|
expect(groupFields).toEqual(groupFieldsExpected);
|
|
71
135
|
});
|
|
72
|
-
it(
|
|
136
|
+
it("schemaToFields should detect zodPeerId as FieldType.id", () => {
|
|
73
137
|
const schema = zod_1.z.object({
|
|
74
|
-
recordId: zod_types_1.zodPeerId.describe(
|
|
75
|
-
optionalRef: zod_types_1.zodPeerId.optional().describe(
|
|
138
|
+
recordId: zod_types_1.zodPeerId.describe("A peer id field"),
|
|
139
|
+
optionalRef: zod_types_1.zodPeerId.optional().describe("An optional peer id"),
|
|
76
140
|
});
|
|
77
141
|
const fields = (0, types_1.schemaToFields)(schema);
|
|
78
|
-
expect(fields.find(f => f.name ===
|
|
79
|
-
expect(fields.find(f => f.name ===
|
|
142
|
+
expect(fields.find((f) => f.name === "recordId")?.type).toBe(field_type_1.FieldType.id);
|
|
143
|
+
expect(fields.find((f) => f.name === "optionalRef")?.type).toBe(field_type_1.FieldType.id);
|
|
80
144
|
});
|
|
81
|
-
it(
|
|
145
|
+
it("schemaToFields should NOT classify plain z.string() as id just because name ends in Id", () => {
|
|
82
146
|
const schema = zod_1.z.object({
|
|
83
|
-
externalId: zod_1.z.string().describe(
|
|
84
|
-
channelId: zod_1.z.string().describe(
|
|
85
|
-
name: zod_1.z.string().describe(
|
|
147
|
+
externalId: zod_1.z.string().describe("An external system identifier"),
|
|
148
|
+
channelId: zod_1.z.string().describe("A channel reference"),
|
|
149
|
+
name: zod_1.z.string().describe("A plain string"),
|
|
86
150
|
});
|
|
87
151
|
const fields = (0, types_1.schemaToFields)(schema);
|
|
88
|
-
expect(fields.find(f => f.name ===
|
|
89
|
-
expect(fields.find(f => f.name ===
|
|
90
|
-
expect(fields.find(f => f.name ===
|
|
152
|
+
expect(fields.find((f) => f.name === "externalId")?.type).toBe(field_type_1.FieldType.string);
|
|
153
|
+
expect(fields.find((f) => f.name === "channelId")?.type).toBe(field_type_1.FieldType.string);
|
|
154
|
+
expect(fields.find((f) => f.name === "name")?.type).toBe(field_type_1.FieldType.string);
|
|
91
155
|
});
|
|
92
|
-
it(
|
|
93
|
-
const zodEmail = zod_1.z.string().refine(val => val.includes(
|
|
94
|
-
const zodNonEmpty = zod_1.z
|
|
156
|
+
it("schemaToFields should NOT classify a non-id string refinement as FieldType.id", () => {
|
|
157
|
+
const zodEmail = zod_1.z.string().refine((val) => val.includes("@"), { message: "Must be an email" });
|
|
158
|
+
const zodNonEmpty = zod_1.z
|
|
159
|
+
.string()
|
|
160
|
+
.refine((val) => val.length > 0, { message: "Must not be empty" });
|
|
95
161
|
const schema = zod_1.z.object({
|
|
96
|
-
email: zodEmail.describe(
|
|
97
|
-
requiredField: zodNonEmpty.describe(
|
|
98
|
-
peerId: zod_types_1.zodPeerId.describe(
|
|
162
|
+
email: zodEmail.describe("An email address"),
|
|
163
|
+
requiredField: zodNonEmpty.describe("A non-empty string"),
|
|
164
|
+
peerId: zod_types_1.zodPeerId.describe("A real peer id"),
|
|
99
165
|
});
|
|
100
166
|
const fields = (0, types_1.schemaToFields)(schema);
|
|
101
|
-
expect(fields.find(f => f.name ===
|
|
102
|
-
expect(fields.find(f => f.name ===
|
|
103
|
-
expect(fields.find(f => f.name ===
|
|
167
|
+
expect(fields.find((f) => f.name === "email")?.type).toBe(field_type_1.FieldType.string);
|
|
168
|
+
expect(fields.find((f) => f.name === "requiredField")?.type).toBe(field_type_1.FieldType.string);
|
|
169
|
+
expect(fields.find((f) => f.name === "peerId")?.type).toBe(field_type_1.FieldType.id);
|
|
104
170
|
});
|
|
105
|
-
it(
|
|
171
|
+
it("fieldsToSchema should merge with optional code schema for most-constrained validation", () => {
|
|
106
172
|
const codeSchema = zod_1.z.object({
|
|
107
|
-
recordId: zod_types_1.zodPeerId.describe(
|
|
108
|
-
label: zod_1.z.string().min(1).describe(
|
|
173
|
+
recordId: zod_types_1.zodPeerId.describe("A peer id"),
|
|
174
|
+
label: zod_1.z.string().min(1).describe("Non-empty label"),
|
|
109
175
|
});
|
|
110
176
|
const fields = [
|
|
111
|
-
{ name:
|
|
112
|
-
{ name:
|
|
177
|
+
{ name: "recordId", description: "A peer id", type: field_type_1.FieldType.string },
|
|
178
|
+
{ name: "label", description: "Non-empty label", type: field_type_1.FieldType.string },
|
|
113
179
|
];
|
|
114
180
|
const mergedSchema = (0, types_1.fieldsToSchema)(fields, codeSchema);
|
|
115
181
|
const validId = (0, utils_1.newid)();
|
|
116
182
|
// Valid peer id should pass the merged schema
|
|
117
|
-
expect(() => mergedSchema.parse({ recordId: validId, label:
|
|
183
|
+
expect(() => mergedSchema.parse({ recordId: validId, label: "hello" })).not.toThrow();
|
|
118
184
|
// Empty string should fail: the code schema's zodPeerId rejects it
|
|
119
|
-
expect(() => mergedSchema.parse({ recordId:
|
|
185
|
+
expect(() => mergedSchema.parse({ recordId: "", label: "hello" })).toThrow();
|
|
120
186
|
// Empty label should fail: the code schema's .min(1) rejects it
|
|
121
|
-
expect(() => mergedSchema.parse({ recordId: validId, label:
|
|
187
|
+
expect(() => mergedSchema.parse({ recordId: validId, label: "" })).toThrow();
|
|
122
188
|
});
|
|
123
|
-
it(
|
|
189
|
+
it("round-trip: fieldsToSchema id fields should survive schemaToFields detection", () => {
|
|
124
190
|
// fieldsToSchema creates z.string().refine(isid) for FieldType.id fields.
|
|
125
191
|
// schemaToFields should detect that refinement as FieldType.id so round-trips are consistent.
|
|
126
192
|
const fields = [
|
|
127
|
-
{ name:
|
|
128
|
-
{ name:
|
|
193
|
+
{ name: "recordId", description: "A peer id", type: field_type_1.FieldType.id },
|
|
194
|
+
{ name: "label", description: "A label", type: field_type_1.FieldType.string },
|
|
129
195
|
];
|
|
130
196
|
const schema = (0, types_1.fieldsToSchema)(fields);
|
|
131
197
|
const roundTrippedFields = (0, types_1.schemaToFields)(schema);
|
|
132
|
-
expect(roundTrippedFields.find(f => f.name ===
|
|
133
|
-
expect(roundTrippedFields.find(f => f.name ===
|
|
198
|
+
expect(roundTrippedFields.find((f) => f.name === "recordId")?.type).toBe(field_type_1.FieldType.id);
|
|
199
|
+
expect(roundTrippedFields.find((f) => f.name === "label")?.type).toBe(field_type_1.FieldType.string);
|
|
134
200
|
});
|
|
135
|
-
it(
|
|
201
|
+
it("fieldsToSchema merge should handle optional zodPeerId fields correctly", () => {
|
|
136
202
|
const codeSchema = zod_1.z.object({
|
|
137
|
-
ownerId: zod_types_1.zodPeerId.describe(
|
|
138
|
-
referrerId: zod_types_1.zodPeerId.optional().describe(
|
|
203
|
+
ownerId: zod_types_1.zodPeerId.describe("The owner"),
|
|
204
|
+
referrerId: zod_types_1.zodPeerId.optional().describe("Optional referrer"),
|
|
139
205
|
});
|
|
140
206
|
const fields = [
|
|
141
|
-
{ name:
|
|
142
|
-
{
|
|
207
|
+
{ name: "ownerId", description: "The owner", type: field_type_1.FieldType.string },
|
|
208
|
+
{
|
|
209
|
+
name: "referrerId",
|
|
210
|
+
description: "Optional referrer",
|
|
211
|
+
type: field_type_1.FieldType.string,
|
|
212
|
+
optional: true,
|
|
213
|
+
},
|
|
143
214
|
];
|
|
144
215
|
const mergedSchema = (0, types_1.fieldsToSchema)(fields, codeSchema);
|
|
145
216
|
const validId = (0, utils_1.newid)();
|
|
@@ -149,18 +220,21 @@ describe('types', () => {
|
|
|
149
220
|
// Optional field omitted
|
|
150
221
|
expect(() => mergedSchema.parse({ ownerId: validId })).not.toThrow();
|
|
151
222
|
// Optional field present but invalid
|
|
152
|
-
expect(() => mergedSchema.parse({ ownerId: validId, referrerId:
|
|
223
|
+
expect(() => mergedSchema.parse({ ownerId: validId, referrerId: "not-a-valid-id" })).toThrow();
|
|
153
224
|
// Required field missing
|
|
154
225
|
expect(() => mergedSchema.parse({ referrerId: validId })).toThrow();
|
|
155
226
|
// Required field invalid
|
|
156
|
-
expect(() => mergedSchema.parse({ ownerId:
|
|
227
|
+
expect(() => mergedSchema.parse({ ownerId: "bad", referrerId: validId })).toThrow();
|
|
157
228
|
});
|
|
158
|
-
it(
|
|
229
|
+
it("initRecord pattern: code schema defaults should work even after JSON round-trip of fields", () => {
|
|
159
230
|
const codeSchema = zod_1.z.object({
|
|
160
|
-
recordId: zod_types_1.zodPeerId.describe(
|
|
161
|
-
label: zod_1.z.string().default(
|
|
162
|
-
createdAt: zod_1.z
|
|
163
|
-
|
|
231
|
+
recordId: zod_types_1.zodPeerId.describe("A peer id"),
|
|
232
|
+
label: zod_1.z.string().default("untitled").describe("A label with default"),
|
|
233
|
+
createdAt: zod_1.z
|
|
234
|
+
.date()
|
|
235
|
+
.default(() => new Date())
|
|
236
|
+
.describe("Date with factory default"),
|
|
237
|
+
count: zod_1.z.number().default(0).describe("A count with default"),
|
|
164
238
|
});
|
|
165
239
|
// Simulate the real flow: code schema -> fields -> JSON (sync) -> parse back
|
|
166
240
|
const fields = (0, types_1.schemaToFields)(codeSchema);
|
|
@@ -188,19 +262,19 @@ describe('types', () => {
|
|
|
188
262
|
}
|
|
189
263
|
}
|
|
190
264
|
const result = { ...defaults, ...data };
|
|
191
|
-
expect(result.label).toBe(
|
|
265
|
+
expect(result.label).toBe("untitled");
|
|
192
266
|
expect(result.createdAt).toBeInstanceOf(Date);
|
|
193
267
|
expect(result.count).toBe(0);
|
|
194
268
|
expect(result.recordId).toBe(validId);
|
|
195
269
|
});
|
|
196
|
-
it(
|
|
270
|
+
it("fieldsToSchema without code schema should work as before", () => {
|
|
197
271
|
const fields = [
|
|
198
|
-
{ name:
|
|
199
|
-
{ name:
|
|
272
|
+
{ name: "recordId", description: "A peer id", type: field_type_1.FieldType.id },
|
|
273
|
+
{ name: "label", description: "A label", type: field_type_1.FieldType.string },
|
|
200
274
|
];
|
|
201
275
|
const schema = (0, types_1.fieldsToSchema)(fields);
|
|
202
276
|
const validId = (0, utils_1.newid)();
|
|
203
|
-
expect(() => schema.parse({ recordId: validId, label:
|
|
204
|
-
expect(() => schema.parse({ recordId:
|
|
277
|
+
expect(() => schema.parse({ recordId: validId, label: "hello" })).not.toThrow();
|
|
278
|
+
expect(() => schema.parse({ recordId: "", label: "hello" })).toThrow();
|
|
205
279
|
});
|
|
206
280
|
});
|
|
@@ -10,9 +10,9 @@ const group_permissions_1 = require("./group-permissions");
|
|
|
10
10
|
*/
|
|
11
11
|
async function verifyPackageSignature(packageObj, groupId) {
|
|
12
12
|
(0, keys_1.verifyObjectSignature)(packageObj);
|
|
13
|
-
const signerPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(packageObj) ??
|
|
13
|
+
const signerPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(packageObj) ?? "";
|
|
14
14
|
const signerRole = await (0, group_permissions_1.getUserRoleFromPublicKey)(groupId, signerPublicKey);
|
|
15
15
|
if (signerRole < group_permissions_1.GroupMemberRole.Admin) {
|
|
16
|
-
throw new Error(
|
|
16
|
+
throw new Error("Only group admins can create or update packages");
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IPackageVersion } from
|
|
1
|
+
import type { IPackageVersion } from "./package-versions";
|
|
2
2
|
/**
|
|
3
3
|
* Verifies that a package version update signature is valid, throws on invalid signature
|
|
4
4
|
* @param packageVersion The package version record to verify
|
|
@@ -10,9 +10,9 @@ const group_permissions_1 = require("./group-permissions");
|
|
|
10
10
|
*/
|
|
11
11
|
async function verifyPackageVersionSignature(packageVersion, groupId) {
|
|
12
12
|
(0, keys_1.verifyObjectSignature)(packageVersion);
|
|
13
|
-
const signerPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(packageVersion) ??
|
|
13
|
+
const signerPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(packageVersion) ?? "";
|
|
14
14
|
const signerRole = await (0, group_permissions_1.getUserRoleFromPublicKey)(groupId, signerPublicKey);
|
|
15
15
|
if (signerRole < group_permissions_1.GroupMemberRole.Admin) {
|
|
16
|
-
throw new Error(
|
|
16
|
+
throw new Error("Only group admins can create or update package versions");
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -34,15 +34,15 @@ declare const schema: z.ZodObject<{
|
|
|
34
34
|
createdBy: z.ZodEffects<z.ZodString, string, string>;
|
|
35
35
|
createdAt: z.ZodString;
|
|
36
36
|
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
version: string;
|
|
37
38
|
signature: string;
|
|
38
|
-
createdBy: string;
|
|
39
|
-
createdAt: string;
|
|
40
|
-
packageId: string;
|
|
41
39
|
packageVersionId: string;
|
|
42
|
-
|
|
40
|
+
packageId: string;
|
|
43
41
|
packageVersionHash: string;
|
|
44
42
|
packageBundleFileId: string;
|
|
45
43
|
packageBundleFileHash: string;
|
|
44
|
+
createdBy: string;
|
|
45
|
+
createdAt: string;
|
|
46
46
|
versionTag?: string | undefined;
|
|
47
47
|
routesBundleFileId?: string | undefined;
|
|
48
48
|
routesBundleFileHash?: string | undefined;
|
|
@@ -55,15 +55,15 @@ declare const schema: z.ZodObject<{
|
|
|
55
55
|
displayName?: string | undefined;
|
|
56
56
|
}[] | undefined;
|
|
57
57
|
}, {
|
|
58
|
+
version: string;
|
|
58
59
|
signature: string;
|
|
59
|
-
createdBy: string;
|
|
60
|
-
createdAt: string;
|
|
61
|
-
packageId: string;
|
|
62
60
|
packageVersionId: string;
|
|
63
|
-
|
|
61
|
+
packageId: string;
|
|
64
62
|
packageVersionHash: string;
|
|
65
63
|
packageBundleFileId: string;
|
|
66
64
|
packageBundleFileHash: string;
|
|
65
|
+
createdBy: string;
|
|
66
|
+
createdAt: string;
|
|
67
67
|
versionTag?: string | undefined;
|
|
68
68
|
routesBundleFileId?: string | undefined;
|
|
69
69
|
routesBundleFileHash?: string | undefined;
|
|
@@ -91,7 +91,7 @@ export declare function PackageVersions(dataContext?: DataContext): PackageVersi
|
|
|
91
91
|
* Compute a hash combining the bundle file hashes to uniquely identify this version's content.
|
|
92
92
|
*/
|
|
93
93
|
export declare function computePackageVersionHash(version: string, versionTag: string, packageBundleFileHash: string, routesBundleFileHash?: string, uiBundleFileHash?: string): string;
|
|
94
|
-
export declare function isVersionInRange(activeVersion: string, incomingVersion: string, range:
|
|
94
|
+
export declare function isVersionInRange(activeVersion: string, incomingVersion: string, range: "pinned" | "patch" | "minor" | "latest"): boolean;
|
|
95
95
|
/**
|
|
96
96
|
* Returns true if incomingVersion is strictly newer than activeVersion (semver comparison).
|
|
97
97
|
*/
|