@geoprotocol/grc-20 0.1.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.
Files changed (82) hide show
  1. package/dist/builder/edit.d.ts +107 -0
  2. package/dist/builder/edit.d.ts.map +1 -0
  3. package/dist/builder/edit.js +221 -0
  4. package/dist/builder/edit.js.map +1 -0
  5. package/dist/builder/entity.d.ts +62 -0
  6. package/dist/builder/entity.d.ts.map +1 -0
  7. package/dist/builder/entity.js +126 -0
  8. package/dist/builder/entity.js.map +1 -0
  9. package/dist/builder/index.d.ts +5 -0
  10. package/dist/builder/index.d.ts.map +1 -0
  11. package/dist/builder/index.js +5 -0
  12. package/dist/builder/index.js.map +1 -0
  13. package/dist/builder/relation.d.ts +66 -0
  14. package/dist/builder/relation.d.ts.map +1 -0
  15. package/dist/builder/relation.js +114 -0
  16. package/dist/builder/relation.js.map +1 -0
  17. package/dist/builder/update.d.ts +90 -0
  18. package/dist/builder/update.d.ts.map +1 -0
  19. package/dist/builder/update.js +174 -0
  20. package/dist/builder/update.js.map +1 -0
  21. package/dist/codec/edit.d.ts +17 -0
  22. package/dist/codec/edit.d.ts.map +1 -0
  23. package/dist/codec/edit.js +393 -0
  24. package/dist/codec/edit.js.map +1 -0
  25. package/dist/codec/index.d.ts +3 -0
  26. package/dist/codec/index.d.ts.map +1 -0
  27. package/dist/codec/index.js +3 -0
  28. package/dist/codec/index.js.map +1 -0
  29. package/dist/codec/op.d.ts +27 -0
  30. package/dist/codec/op.d.ts.map +1 -0
  31. package/dist/codec/op.js +333 -0
  32. package/dist/codec/op.js.map +1 -0
  33. package/dist/codec/primitives.d.ts +138 -0
  34. package/dist/codec/primitives.d.ts.map +1 -0
  35. package/dist/codec/primitives.js +285 -0
  36. package/dist/codec/primitives.js.map +1 -0
  37. package/dist/codec/value.d.ts +41 -0
  38. package/dist/codec/value.d.ts.map +1 -0
  39. package/dist/codec/value.js +202 -0
  40. package/dist/codec/value.js.map +1 -0
  41. package/dist/genesis/index.d.ts +109 -0
  42. package/dist/genesis/index.d.ts.map +1 -0
  43. package/dist/genesis/index.js +183 -0
  44. package/dist/genesis/index.js.map +1 -0
  45. package/dist/index.d.ts +13 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +18 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/test/basic.test.d.ts +2 -0
  50. package/dist/test/basic.test.d.ts.map +1 -0
  51. package/dist/test/basic.test.js +270 -0
  52. package/dist/test/basic.test.js.map +1 -0
  53. package/dist/types/edit.d.ts +46 -0
  54. package/dist/types/edit.d.ts.map +1 -0
  55. package/dist/types/edit.js +13 -0
  56. package/dist/types/edit.js.map +1 -0
  57. package/dist/types/id.d.ts +32 -0
  58. package/dist/types/id.d.ts.map +1 -0
  59. package/dist/types/id.js +45 -0
  60. package/dist/types/id.js.map +1 -0
  61. package/dist/types/index.d.ts +9 -0
  62. package/dist/types/index.d.ts.map +1 -0
  63. package/dist/types/index.js +5 -0
  64. package/dist/types/index.js.map +1 -0
  65. package/dist/types/op.d.ts +147 -0
  66. package/dist/types/op.d.ts.map +1 -0
  67. package/dist/types/op.js +60 -0
  68. package/dist/types/op.js.map +1 -0
  69. package/dist/types/value.d.ts +107 -0
  70. package/dist/types/value.d.ts.map +1 -0
  71. package/dist/types/value.js +126 -0
  72. package/dist/types/value.js.map +1 -0
  73. package/dist/util/id.d.ts +51 -0
  74. package/dist/util/id.d.ts.map +1 -0
  75. package/dist/util/id.js +215 -0
  76. package/dist/util/id.js.map +1 -0
  77. package/dist/util/index.d.ts +2 -0
  78. package/dist/util/index.d.ts.map +1 -0
  79. package/dist/util/index.js +2 -0
  80. package/dist/util/index.js.map +1 -0
  81. package/package.json +68 -0
  82. package/readme.md +232 -0
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Creates an Id from a Uint8Array.
3
+ * @throws Error if the array is not exactly 16 bytes.
4
+ */
5
+ export function createId(bytes) {
6
+ if (bytes.length !== 16) {
7
+ throw new Error(`Id must be 16 bytes, got ${bytes.length}`);
8
+ }
9
+ return bytes;
10
+ }
11
+ /**
12
+ * Creates a copy of an Id.
13
+ */
14
+ export function copyId(id) {
15
+ const copy = new Uint8Array(16);
16
+ copy.set(id);
17
+ return copy;
18
+ }
19
+ /**
20
+ * The nil/zero UUID.
21
+ */
22
+ export const NIL_ID = createId(new Uint8Array(16));
23
+ /**
24
+ * Compares two Ids for equality.
25
+ */
26
+ export function idsEqual(a, b) {
27
+ for (let i = 0; i < 16; i++) {
28
+ if (a[i] !== b[i])
29
+ return false;
30
+ }
31
+ return true;
32
+ }
33
+ /**
34
+ * Compares two Ids lexicographically.
35
+ * Returns negative if a < b, 0 if a === b, positive if a > b.
36
+ */
37
+ export function compareIds(a, b) {
38
+ for (let i = 0; i < 16; i++) {
39
+ if (a[i] !== b[i]) {
40
+ return a[i] - b[i];
41
+ }
42
+ }
43
+ return 0;
44
+ }
45
+ //# sourceMappingURL=id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.js","sourceRoot":"","sources":["../../src/types/id.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAiB;IACxC,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,KAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,EAAM;IAC3B,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACb,OAAO,IAAU,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAO,QAAQ,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAK,EAAE,CAAK;IACnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,CAAK,EAAE,CAAK;IACrC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAClB,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,9 @@
1
+ export type { Id } from "./id.js";
2
+ export { createId, copyId, NIL_ID, idsEqual, compareIds, } from "./id.js";
3
+ export type { Value, PropertyValue, Property, DecimalMantissa, } from "./value.js";
4
+ export { DataType, EmbeddingSubType, embeddingBytesForDims, valueDataType, validateValue, } from "./value.js";
5
+ export type { Op, CreateEntity, UpdateEntity, DeleteEntity, RestoreEntity, CreateRelation, UpdateRelation, DeleteRelation, RestoreRelation, CreateProperty, RelationIdMode, UnsetLanguage, UnsetProperty, } from "./op.js";
6
+ export { opTypeCode, validatePosition, OP_TYPE_CREATE_ENTITY, OP_TYPE_UPDATE_ENTITY, OP_TYPE_DELETE_ENTITY, OP_TYPE_RESTORE_ENTITY, OP_TYPE_CREATE_RELATION, OP_TYPE_UPDATE_RELATION, OP_TYPE_DELETE_RELATION, OP_TYPE_RESTORE_RELATION, OP_TYPE_CREATE_PROPERTY, } from "./op.js";
7
+ export type { Edit, WireDictionaries } from "./edit.js";
8
+ export { createWireDictionaries } from "./edit.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,UAAU,GACX,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,KAAK,EACL,aAAa,EACb,QAAQ,EACR,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,aAAa,GACd,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,EAAE,EACF,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createId, copyId, NIL_ID, idsEqual, compareIds, } from "./id.js";
2
+ export { DataType, EmbeddingSubType, embeddingBytesForDims, valueDataType, validateValue, } from "./value.js";
3
+ export { opTypeCode, validatePosition, OP_TYPE_CREATE_ENTITY, OP_TYPE_UPDATE_ENTITY, OP_TYPE_DELETE_ENTITY, OP_TYPE_RESTORE_ENTITY, OP_TYPE_CREATE_RELATION, OP_TYPE_UPDATE_RELATION, OP_TYPE_DELETE_RELATION, OP_TYPE_RESTORE_RELATION, OP_TYPE_CREATE_PROPERTY, } from "./op.js";
4
+ export { createWireDictionaries } from "./edit.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,UAAU,GACX,MAAM,SAAS,CAAC;AASjB,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,aAAa,GACd,MAAM,YAAY,CAAC;AAkBpB,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,147 @@
1
+ import type { Id } from "./id.js";
2
+ import type { DataType, PropertyValue } from "./value.js";
3
+ /**
4
+ * Relation ID mode for CreateRelation.
5
+ */
6
+ export type RelationIdMode = {
7
+ type: "unique";
8
+ } | {
9
+ type: "many";
10
+ id: Id;
11
+ };
12
+ /**
13
+ * Specifies which language slot to clear for an UnsetProperty.
14
+ */
15
+ export type UnsetLanguage = {
16
+ type: "all";
17
+ } | {
18
+ type: "nonLinguistic";
19
+ } | {
20
+ type: "specific";
21
+ language: Id;
22
+ };
23
+ /**
24
+ * Specifies a property to unset, with optional language targeting (TEXT only).
25
+ */
26
+ export interface UnsetProperty {
27
+ property: Id;
28
+ language: UnsetLanguage;
29
+ }
30
+ /**
31
+ * Creates an entity (spec Section 3.2).
32
+ *
33
+ * If the entity does not exist, creates it. If it already exists,
34
+ * this acts as an update: values are applied as set_properties (LWW).
35
+ */
36
+ export interface CreateEntity {
37
+ type: "createEntity";
38
+ id: Id;
39
+ values: PropertyValue[];
40
+ }
41
+ /**
42
+ * Updates an existing entity (spec Section 3.2).
43
+ *
44
+ * Application order within op:
45
+ * 1. unsetProperties
46
+ * 2. setProperties
47
+ */
48
+ export interface UpdateEntity {
49
+ type: "updateEntity";
50
+ id: Id;
51
+ setProperties: PropertyValue[];
52
+ unsetProperties: UnsetProperty[];
53
+ }
54
+ /**
55
+ * Deletes an entity (spec Section 3.2).
56
+ *
57
+ * Transitions the entity to DELETED state.
58
+ */
59
+ export interface DeleteEntity {
60
+ type: "deleteEntity";
61
+ id: Id;
62
+ }
63
+ /**
64
+ * Restores a deleted entity (spec Section 3.2).
65
+ */
66
+ export interface RestoreEntity {
67
+ type: "restoreEntity";
68
+ id: Id;
69
+ }
70
+ /**
71
+ * Creates a relation (spec Section 3.3).
72
+ */
73
+ export interface CreateRelation {
74
+ type: "createRelation";
75
+ idMode: RelationIdMode;
76
+ relationType: Id;
77
+ from: Id;
78
+ to: Id;
79
+ fromSpace?: Id;
80
+ fromVersion?: Id;
81
+ toSpace?: Id;
82
+ toVersion?: Id;
83
+ entity?: Id;
84
+ position?: string;
85
+ }
86
+ /**
87
+ * Updates a relation's position (spec Section 3.3).
88
+ *
89
+ * All other fields are immutable.
90
+ */
91
+ export interface UpdateRelation {
92
+ type: "updateRelation";
93
+ id: Id;
94
+ position?: string;
95
+ }
96
+ /**
97
+ * Deletes a relation (spec Section 3.3).
98
+ */
99
+ export interface DeleteRelation {
100
+ type: "deleteRelation";
101
+ id: Id;
102
+ }
103
+ /**
104
+ * Restores a deleted relation (spec Section 3.3).
105
+ */
106
+ export interface RestoreRelation {
107
+ type: "restoreRelation";
108
+ id: Id;
109
+ }
110
+ /**
111
+ * Creates a property in the schema (spec Section 3.4).
112
+ */
113
+ export interface CreateProperty {
114
+ type: "createProperty";
115
+ id: Id;
116
+ dataType: DataType;
117
+ }
118
+ /**
119
+ * An atomic operation that modifies graph state (spec Section 3.1).
120
+ */
121
+ export type Op = CreateEntity | UpdateEntity | DeleteEntity | RestoreEntity | CreateRelation | UpdateRelation | DeleteRelation | RestoreRelation | CreateProperty;
122
+ /**
123
+ * Op type codes for wire encoding.
124
+ */
125
+ export declare const OP_TYPE_CREATE_ENTITY = 1;
126
+ export declare const OP_TYPE_UPDATE_ENTITY = 2;
127
+ export declare const OP_TYPE_DELETE_ENTITY = 3;
128
+ export declare const OP_TYPE_RESTORE_ENTITY = 4;
129
+ export declare const OP_TYPE_CREATE_RELATION = 5;
130
+ export declare const OP_TYPE_UPDATE_RELATION = 6;
131
+ export declare const OP_TYPE_DELETE_RELATION = 7;
132
+ export declare const OP_TYPE_RESTORE_RELATION = 8;
133
+ export declare const OP_TYPE_CREATE_PROPERTY = 9;
134
+ /**
135
+ * Returns the op type code for wire encoding.
136
+ */
137
+ export declare function opTypeCode(op: Op): number;
138
+ /**
139
+ * Validates a position string according to spec rules.
140
+ *
141
+ * Position strings must:
142
+ * - Not be empty
143
+ * - Only contain characters 0-9, A-Z, a-z (62 chars, ASCII order)
144
+ * - Not exceed 64 characters
145
+ */
146
+ export declare function validatePosition(pos: string): string | undefined;
147
+ //# sourceMappingURL=op.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"op.d.ts","sourceRoot":"","sources":["../../src/types/op.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,EAAE,CAAA;CAAE,CAAC;AAE7B;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EA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;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,EAAE,EAAE,EAAE,CAAC;CACR;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,iBAAiB,CAAC;IACxB,EAAE,EAAE,EAAE,CAAC;CACR;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,gBAAgB,CAAC;IACvB,EAAE,EAAE,EAAE,CAAC;IACP,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,EAAE,GACV,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,cAAc,GACd,cAAc,GACd,cAAc,GACd,eAAe,GACf,cAAc,CAAC;AAEnB;;GAEG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC,eAAO,MAAM,sBAAsB,IAAI,CAAC;AACxC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC;;GAEG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CAqBzC;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAahE"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Op type codes for wire encoding.
3
+ */
4
+ export const OP_TYPE_CREATE_ENTITY = 1;
5
+ export const OP_TYPE_UPDATE_ENTITY = 2;
6
+ export const OP_TYPE_DELETE_ENTITY = 3;
7
+ export const OP_TYPE_RESTORE_ENTITY = 4;
8
+ export const OP_TYPE_CREATE_RELATION = 5;
9
+ export const OP_TYPE_UPDATE_RELATION = 6;
10
+ export const OP_TYPE_DELETE_RELATION = 7;
11
+ export const OP_TYPE_RESTORE_RELATION = 8;
12
+ export const OP_TYPE_CREATE_PROPERTY = 9;
13
+ /**
14
+ * Returns the op type code for wire encoding.
15
+ */
16
+ export function opTypeCode(op) {
17
+ switch (op.type) {
18
+ case "createEntity":
19
+ return OP_TYPE_CREATE_ENTITY;
20
+ case "updateEntity":
21
+ return OP_TYPE_UPDATE_ENTITY;
22
+ case "deleteEntity":
23
+ return OP_TYPE_DELETE_ENTITY;
24
+ case "restoreEntity":
25
+ return OP_TYPE_RESTORE_ENTITY;
26
+ case "createRelation":
27
+ return OP_TYPE_CREATE_RELATION;
28
+ case "updateRelation":
29
+ return OP_TYPE_UPDATE_RELATION;
30
+ case "deleteRelation":
31
+ return OP_TYPE_DELETE_RELATION;
32
+ case "restoreRelation":
33
+ return OP_TYPE_RESTORE_RELATION;
34
+ case "createProperty":
35
+ return OP_TYPE_CREATE_PROPERTY;
36
+ }
37
+ }
38
+ /**
39
+ * Validates a position string according to spec rules.
40
+ *
41
+ * Position strings must:
42
+ * - Not be empty
43
+ * - Only contain characters 0-9, A-Z, a-z (62 chars, ASCII order)
44
+ * - Not exceed 64 characters
45
+ */
46
+ export function validatePosition(pos) {
47
+ if (pos.length === 0) {
48
+ return "position cannot be empty";
49
+ }
50
+ if (pos.length > 64) {
51
+ return "position exceeds 64 characters";
52
+ }
53
+ for (const c of pos) {
54
+ if (!/^[0-9A-Za-z]$/.test(c)) {
55
+ return `position contains invalid character: ${c}`;
56
+ }
57
+ }
58
+ return undefined;
59
+ }
60
+ //# sourceMappingURL=op.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"op.js","sourceRoot":"","sources":["../../src/types/op.ts"],"names":[],"mappings":"AAyIA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,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,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7B,OAAO,wCAAwC,CAAC,EAAE,CAAC;QACrD,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,107 @@
1
+ import type { Id } from "./id.js";
2
+ /**
3
+ * Data types for property values (spec Section 2.4).
4
+ */
5
+ export declare enum DataType {
6
+ Bool = 1,
7
+ Int64 = 2,
8
+ Float64 = 3,
9
+ Decimal = 4,
10
+ Text = 5,
11
+ Bytes = 6,
12
+ Timestamp = 7,
13
+ Date = 8,
14
+ Point = 9,
15
+ Embedding = 10
16
+ }
17
+ /**
18
+ * Embedding sub-types (spec Section 2.4).
19
+ */
20
+ export declare enum EmbeddingSubType {
21
+ /** 32-bit IEEE 754 float, little-endian (4 bytes per dim) */
22
+ Float32 = 0,
23
+ /** Signed 8-bit integer (1 byte per dim) */
24
+ Int8 = 1,
25
+ /** Bit-packed binary, LSB-first (1/8 byte per dim) */
26
+ Binary = 2
27
+ }
28
+ /**
29
+ * Returns the number of bytes needed for the given number of dimensions.
30
+ */
31
+ export declare function embeddingBytesForDims(subType: EmbeddingSubType, dims: number): number;
32
+ /**
33
+ * Decimal mantissa representation.
34
+ */
35
+ export type DecimalMantissa = {
36
+ type: "i64";
37
+ value: bigint;
38
+ } | {
39
+ type: "big";
40
+ bytes: Uint8Array;
41
+ };
42
+ /**
43
+ * A typed value that can be stored on an entity or relation.
44
+ */
45
+ export type Value = {
46
+ type: "bool";
47
+ value: boolean;
48
+ } | {
49
+ type: "int64";
50
+ value: bigint;
51
+ unit?: Id;
52
+ } | {
53
+ type: "float64";
54
+ value: number;
55
+ unit?: Id;
56
+ } | {
57
+ type: "decimal";
58
+ exponent: number;
59
+ mantissa: DecimalMantissa;
60
+ unit?: Id;
61
+ } | {
62
+ type: "text";
63
+ value: string;
64
+ language?: Id;
65
+ } | {
66
+ type: "bytes";
67
+ value: Uint8Array;
68
+ } | {
69
+ type: "timestamp";
70
+ value: bigint;
71
+ } | {
72
+ type: "date";
73
+ value: string;
74
+ } | {
75
+ type: "point";
76
+ lat: number;
77
+ lon: number;
78
+ } | {
79
+ type: "embedding";
80
+ subType: EmbeddingSubType;
81
+ dims: number;
82
+ data: Uint8Array;
83
+ };
84
+ /**
85
+ * Returns the DataType for a Value.
86
+ */
87
+ export declare function valueDataType(value: Value): DataType;
88
+ /**
89
+ * A property-value pair that can be attached to an object.
90
+ */
91
+ export interface PropertyValue {
92
+ property: Id;
93
+ value: Value;
94
+ }
95
+ /**
96
+ * A property definition in the schema.
97
+ */
98
+ export interface Property {
99
+ id: Id;
100
+ dataType: DataType;
101
+ }
102
+ /**
103
+ * Validates a value according to spec rules.
104
+ * Returns an error message if invalid, undefined if valid.
105
+ */
106
+ export declare function validateValue(value: Value): string | undefined;
107
+ //# sourceMappingURL=value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../src/types/value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC;;GAEG;AACH,oBAAY,QAAQ;IAClB,IAAI,IAAI;IACR,KAAK,IAAI;IACT,OAAO,IAAI;IACX,OAAO,IAAI;IACX,IAAI,IAAI;IACR,KAAK,IAAI;IACT,SAAS,IAAI;IACb,IAAI,IAAI;IACR,KAAK,IAAI;IACT,SAAS,KAAK;CACf;AAED;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,6DAA6D;IAC7D,OAAO,IAAI;IACX,4CAA4C;IAC5C,IAAI,IAAI;IACR,sDAAsD;IACtD,MAAM,IAAI;CACX;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CASrF;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE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AQ,EAAE,EAAE,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,EAAE,CAAC;IACP,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAqD9D"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Data types for property values (spec Section 2.4).
3
+ */
4
+ export var DataType;
5
+ (function (DataType) {
6
+ DataType[DataType["Bool"] = 1] = "Bool";
7
+ DataType[DataType["Int64"] = 2] = "Int64";
8
+ DataType[DataType["Float64"] = 3] = "Float64";
9
+ DataType[DataType["Decimal"] = 4] = "Decimal";
10
+ DataType[DataType["Text"] = 5] = "Text";
11
+ DataType[DataType["Bytes"] = 6] = "Bytes";
12
+ DataType[DataType["Timestamp"] = 7] = "Timestamp";
13
+ DataType[DataType["Date"] = 8] = "Date";
14
+ DataType[DataType["Point"] = 9] = "Point";
15
+ DataType[DataType["Embedding"] = 10] = "Embedding";
16
+ })(DataType || (DataType = {}));
17
+ /**
18
+ * Embedding sub-types (spec Section 2.4).
19
+ */
20
+ export var EmbeddingSubType;
21
+ (function (EmbeddingSubType) {
22
+ /** 32-bit IEEE 754 float, little-endian (4 bytes per dim) */
23
+ EmbeddingSubType[EmbeddingSubType["Float32"] = 0] = "Float32";
24
+ /** Signed 8-bit integer (1 byte per dim) */
25
+ EmbeddingSubType[EmbeddingSubType["Int8"] = 1] = "Int8";
26
+ /** Bit-packed binary, LSB-first (1/8 byte per dim) */
27
+ EmbeddingSubType[EmbeddingSubType["Binary"] = 2] = "Binary";
28
+ })(EmbeddingSubType || (EmbeddingSubType = {}));
29
+ /**
30
+ * Returns the number of bytes needed for the given number of dimensions.
31
+ */
32
+ export function embeddingBytesForDims(subType, dims) {
33
+ switch (subType) {
34
+ case EmbeddingSubType.Float32:
35
+ return dims * 4;
36
+ case EmbeddingSubType.Int8:
37
+ return dims;
38
+ case EmbeddingSubType.Binary:
39
+ return Math.ceil(dims / 8);
40
+ }
41
+ }
42
+ /**
43
+ * Returns the DataType for a Value.
44
+ */
45
+ export function valueDataType(value) {
46
+ switch (value.type) {
47
+ case "bool":
48
+ return DataType.Bool;
49
+ case "int64":
50
+ return DataType.Int64;
51
+ case "float64":
52
+ return DataType.Float64;
53
+ case "decimal":
54
+ return DataType.Decimal;
55
+ case "text":
56
+ return DataType.Text;
57
+ case "bytes":
58
+ return DataType.Bytes;
59
+ case "timestamp":
60
+ return DataType.Timestamp;
61
+ case "date":
62
+ return DataType.Date;
63
+ case "point":
64
+ return DataType.Point;
65
+ case "embedding":
66
+ return DataType.Embedding;
67
+ }
68
+ }
69
+ /**
70
+ * Validates a value according to spec rules.
71
+ * Returns an error message if invalid, undefined if valid.
72
+ */
73
+ export function validateValue(value) {
74
+ switch (value.type) {
75
+ case "float64":
76
+ if (Number.isNaN(value.value)) {
77
+ return "NaN is not allowed in Float64";
78
+ }
79
+ break;
80
+ case "decimal": {
81
+ const isZero = value.mantissa.type === "i64"
82
+ ? value.mantissa.value === 0n
83
+ : value.mantissa.bytes.every((b) => b === 0);
84
+ if (isZero && value.exponent !== 0) {
85
+ return "zero DECIMAL must have exponent 0";
86
+ }
87
+ // Check for trailing zeros in non-zero mantissa
88
+ if (!isZero && value.mantissa.type === "i64") {
89
+ if (value.mantissa.value % 10n === 0n) {
90
+ return "DECIMAL mantissa has trailing zeros (not normalized)";
91
+ }
92
+ }
93
+ break;
94
+ }
95
+ case "point":
96
+ if (value.lat < -90 || value.lat > 90) {
97
+ return "latitude out of range [-90, +90]";
98
+ }
99
+ if (value.lon < -180 || value.lon > 180) {
100
+ return "longitude out of range [-180, +180]";
101
+ }
102
+ if (Number.isNaN(value.lat) || Number.isNaN(value.lon)) {
103
+ return "NaN is not allowed in Point coordinates";
104
+ }
105
+ break;
106
+ case "embedding": {
107
+ const expected = embeddingBytesForDims(value.subType, value.dims);
108
+ if (value.data.length !== expected) {
109
+ return `embedding data length ${value.data.length} doesn't match expected ${expected} for ${value.dims} dims`;
110
+ }
111
+ // Check for NaN in float32 embeddings
112
+ if (value.subType === EmbeddingSubType.Float32) {
113
+ const view = new DataView(value.data.buffer, value.data.byteOffset, value.data.byteLength);
114
+ for (let i = 0; i < value.dims; i++) {
115
+ const f = view.getFloat32(i * 4, true);
116
+ if (Number.isNaN(f)) {
117
+ return "NaN is not allowed in float32 embedding";
118
+ }
119
+ }
120
+ }
121
+ break;
122
+ }
123
+ }
124
+ return undefined;
125
+ }
126
+ //# sourceMappingURL=value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.js","sourceRoot":"","sources":["../../src/types/value.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAN,IAAY,QAWX;AAXD,WAAY,QAAQ;IAClB,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,6CAAW,CAAA;IACX,6CAAW,CAAA;IACX,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,iDAAa,CAAA;IACb,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,kDAAc,CAAA;AAChB,CAAC,EAXW,QAAQ,KAAR,QAAQ,QAWnB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,gBAOX;AAPD,WAAY,gBAAgB;IAC1B,6DAA6D;IAC7D,6DAAW,CAAA;IACX,4CAA4C;IAC5C,uDAAQ,CAAA;IACR,sDAAsD;IACtD,2DAAU,CAAA;AACZ,CAAC,EAPW,gBAAgB,KAAhB,gBAAgB,QAO3B;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAyB,EAAE,IAAY;IAC3E,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,gBAAgB,CAAC,OAAO;YAC3B,OAAO,IAAI,GAAG,CAAC,CAAC;QAClB,KAAK,gBAAgB,CAAC,IAAI;YACxB,OAAO,IAAI,CAAC;QACd,KAAK,gBAAgB,CAAC,MAAM;YAC1B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AK,gBAAgB,CAAC,OAAO,EAAE,CAAC;gBAC/C,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC3F,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;oBACpC,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;oBACvC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;wBACpB,OAAO,yCAAyC,CAAC;oBACnD,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { type Id } from "../types/id.js";
2
+ export type { Id } from "../types/id.js";
3
+ /**
4
+ * Formats a UUID as non-hyphenated lowercase hex (recommended display format).
5
+ */
6
+ export declare function formatId(id: Id): string;
7
+ /**
8
+ * Parses a UUID from hex string (with or without hyphens).
9
+ * Returns undefined if the string is invalid.
10
+ */
11
+ export declare function parseId(s: string): Id | undefined;
12
+ /**
13
+ * Generates a random UUIDv4.
14
+ */
15
+ export declare function randomId(): Id;
16
+ /**
17
+ * Derives a UUIDv8 from input bytes using SHA-256.
18
+ *
19
+ * This implements the `derived_uuid` function from spec Section 2.1:
20
+ * ```
21
+ * hash = SHA-256(input_bytes)[0:16]
22
+ * hash[6] = (hash[6] & 0x0F) | 0x80 // version 8
23
+ * hash[8] = (hash[8] & 0x3F) | 0x80 // RFC 4122 variant
24
+ * ```
25
+ */
26
+ export declare function derivedUuid(input: Uint8Array): Id;
27
+ /**
28
+ * Async version of derivedUuid using Web Crypto API.
29
+ */
30
+ export declare function derivedUuidAsync(input: Uint8Array): Promise<Id>;
31
+ /**
32
+ * Derives a UUIDv8 from a string using SHA-256.
33
+ */
34
+ export declare function derivedUuidFromString(input: string): Id;
35
+ /**
36
+ * Derives a unique-mode relation ID.
37
+ *
38
+ * ```
39
+ * id = derived_uuid(from_id || to_id || type_id)
40
+ * ```
41
+ */
42
+ export declare function uniqueRelationId(fromId: Id, toId: Id, typeId: Id): Id;
43
+ /**
44
+ * Derives the reified entity ID from a relation ID.
45
+ *
46
+ * ```
47
+ * entity_id = derived_uuid("grc20:relation-entity:" || relation_id)
48
+ * ```
49
+ */
50
+ export declare function relationEntityId(relationId: Id): Id;
51
+ //# sourceMappingURL=id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/util/id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAGnD,YAAY,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEzC;;GAEG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CAMvC;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,EAAE,GAAG,SAAS,CAgBjD;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,EAAE,CAU7B;AAkID;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,EAAE,CAWjD;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,EAAE,CAAC,CAWrE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,EAAE,CAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,CAMrE;AAID;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,CAKnD"}