@yaks/key 0.0.0-stage → 0.2.36

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 (61) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +108 -2
  3. package/_dist/comp.d.ts +14 -0
  4. package/_dist/comp.d.ts.map +1 -0
  5. package/_dist/eid.d.ts +26 -0
  6. package/_dist/eid.d.ts.map +1 -0
  7. package/_dist/graph.d.ts +6 -0
  8. package/_dist/graph.d.ts.map +1 -0
  9. package/_dist/guard.d.ts +9 -0
  10. package/_dist/guard.d.ts.map +1 -0
  11. package/_dist/keywords.d.ts +8 -0
  12. package/_dist/keywords.d.ts.map +1 -0
  13. package/_dist/kinds.d.ts +14 -0
  14. package/_dist/kinds.d.ts.map +1 -0
  15. package/_dist/mod.d.ts +70 -0
  16. package/_dist/mod.d.ts.map +1 -0
  17. package/_dist/plugin.d.ts +23 -0
  18. package/_dist/plugin.d.ts.map +1 -0
  19. package/_dist/resolve.d.ts +26 -0
  20. package/_dist/resolve.d.ts.map +1 -0
  21. package/_dist/say.d.ts +10 -0
  22. package/_dist/say.d.ts.map +1 -0
  23. package/_dist/vocab.d.ts +9 -0
  24. package/_dist/vocab.d.ts.map +1 -0
  25. package/comp.js +49 -0
  26. package/comp.js.map +1 -0
  27. package/comp.ts +62 -0
  28. package/deno.json +1 -0
  29. package/eid.js +43 -0
  30. package/eid.js.map +1 -0
  31. package/eid.ts +56 -0
  32. package/graph.js +9 -0
  33. package/graph.js.map +1 -0
  34. package/graph.ts +11 -0
  35. package/guard.js +67 -0
  36. package/guard.js.map +1 -0
  37. package/guard.ts +69 -0
  38. package/keywords.js +34 -0
  39. package/keywords.js.map +1 -0
  40. package/keywords.ts +31 -0
  41. package/kinds.js +39 -0
  42. package/kinds.js.map +1 -0
  43. package/kinds.ts +46 -0
  44. package/meta/key.vocab.json +13 -0
  45. package/mod.js +70 -0
  46. package/mod.js.map +1 -0
  47. package/mod.ts +71 -0
  48. package/package.json +26 -4
  49. package/plugin.js +62 -0
  50. package/plugin.js.map +1 -0
  51. package/plugin.ts +58 -0
  52. package/resolve.js +163 -0
  53. package/resolve.js.map +1 -0
  54. package/resolve.ts +155 -0
  55. package/say.js +39 -0
  56. package/say.js.map +1 -0
  57. package/say.ts +37 -0
  58. package/vocab.js +18 -0
  59. package/vocab.js.map +1 -0
  60. package/vocab.json +36 -0
  61. package/vocab.ts +20 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # @yaks/key
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Unique typed values that identify entities — an ISBN, an email address, a short
4
+ name. Each value is stored as its own entity rather than as a property on the
5
+ thing it identifies, and its id is derived from the value, so a value is unique
6
+ within its kind by construction. An entity is a record identified by
7
+ `entity.eid`; components are the named objects stored on that record.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ deno add jsr:@yaks/key
13
+ # or: npx jsr add @yaks/key
14
+ ```
15
+
16
+ ## The idea
17
+
18
+ A key is an entity carrying the `key{of, value}` component plus a second
19
+ component that tags which kind of value it is — `isbn`, `email`, `alias`. The
20
+ application declares these tag components; this package declares only `key`. It
21
+ does not provide a database: key records use the graph's storage adapter. `of`
22
+ points at the entity the value identifies, so one entity can have as many keys
23
+ as you write. It is the same tagged-component pattern
24
+ [@yaks/edge](../edge/README.md) uses for links.
25
+
26
+ ```ts
27
+ import { graph } from '@yaks/graph'
28
+ import { loadVocab } from '@yaks/vocab'
29
+ import { keyDoc, keyed, keyKeywords, keys } from '@yaks/key'
30
+ import { ram } from '@yaks/ram'
31
+
32
+ let library = {
33
+ $defs: {
34
+ book: { component: true, type: 'object', kind: true, properties: {} },
35
+ // one component, and `isbn` is a kind of value
36
+ isbn: { component: true, type: 'object', key: true },
37
+ },
38
+ }
39
+ let vocab = loadVocab([keyDoc, library], [keyKeywords])
40
+ let g = graph({ storage: ram(vocab), vocab, plugins: [keys(vocab)] })
41
+
42
+ await g.apply([
43
+ { entity: { eid: 'b1' }, book: {} },
44
+ keyed('isbn', 'b1', '9780441013593'),
45
+ ])
46
+ ```
47
+
48
+ Alongside the book, that writes this key entity:
49
+
50
+ ```json
51
+ {
52
+ "entity": { "eid": "…derived…" },
53
+ "key": { "of": "b1", "value": "9780441013593" },
54
+ "isbn": {}
55
+ }
56
+ ```
57
+
58
+ ## Four things follow
59
+
60
+ - **A key's id is derived from the value.** `keyEid(kind, value)` returns
61
+ `sha256("<kind>|<value>")` formatted as a UUID, so a value is unique within
62
+ its kind without a separate uniqueness index. A key can be read by its derived
63
+ id using `get`, rather than searched for by value.
64
+ - **A key lives only as long as what it identifies.** `of` is a reference
65
+ declared `death: release`: the row goes when that entity is deleted, and the
66
+ value is free again.
67
+ - **Incomplete keys are refused:** a key with no kind, no value or no `of` never
68
+ reaches storage.
69
+ - **A repeated value can resolve to its existing owner.** When a write creates
70
+ an entity using a temporary `$alias` and gives it a value another entity
71
+ already holds, the write patches that existing entity instead of creating a
72
+ second one — which is what makes a seed, a chunked import, and a page that
73
+ saves itself every time it opens idempotent. A caller who wrote an id down
74
+ rather than using an alias is refused instead, with the holder named. Deleting
75
+ the holder explicitly in the same batch permits a transfer, guarded against
76
+ ownership changing before that batch commits.
77
+
78
+ ## The vocabulary
79
+
80
+ | component | meaning |
81
+ | ---------------- | ------------------------------------------------ |
82
+ | `key{of, value}` | this entity identifies `of` by `value` |
83
+ | your tag | which kind of value it is (declared `key: true`) |
84
+
85
+ A tag component declares which component it accompanies: `key: true` marks a key
86
+ tag, `edge: true` marks an edge tag. Declaring a string instead names the kind
87
+ something other than the component — `key: 'mailbox'` on an `email` component
88
+ means the component written is `email` and the kind queries name is `mailbox`.
89
+
90
+ ## Retiring a value
91
+
92
+ `g.apply([unkeyed('isbn', '9780441013593')])` removes both components and leaves
93
+ the entity itself in place, carrying nothing. The value can then be claimed
94
+ again, by the same entity or another one.
95
+
96
+ ## Exports
97
+
98
+ The root module exports `keyDoc`, `keyKeywords`, `keys(vocab)`, `keyed`,
99
+ `unkeyed`, `keyEid`, and helpers for identifying key tags and reading key
100
+ values. `./vocab` provides declarations and keywords, and `./graph` provides the
101
+ plugin factory used by package loaders. A bundle is a JSON object containing one
102
+ entity's id and components; `keyed` and `unkeyed` return such objects for
103
+ `g.apply()`.
104
+
105
+ ## Composed with
106
+
107
+ [@yaks/alias](https://jsr.io/@yaks/alias) is the kind of key that is a **name**:
108
+ the word a person or an agent types instead of an id, resolved anywhere an eid
109
+ is accepted.
@@ -0,0 +1,14 @@
1
+ import type { Bundle, Comp, Eid } from "@yaks/graph";
2
+ import type { VocabDoc } from "@yaks/vocab";
3
+ /** The property naming the entity the value identifies. */ export declare let OF: string;
4
+ /** The property carrying the value. */ export declare let VALUE: string;
5
+ /**
6
+ * The `key` component as a vocabulary document, to load beside your own:
7
+ * `loadVocab([keyDoc, ...mine], [keyKeywords])`. The kind tags are yours to
8
+ * declare — this document is only the carrier.
9
+ */ export declare let keyDoc: VocabDoc;
10
+ /** The `key` component in a bundle, if it has one. */ export declare let keyOf: (b: Bundle) => Comp | undefined;
11
+ /** The value in a bundle's key. An absent component, a cleared one and an
12
+ * empty string all mean there is no value. */ export declare let valueOf: (b: Bundle) => string | undefined;
13
+ /** The entity a bundle's key identifies, if it identifies one. */ export declare let ofOf: (b: Bundle | undefined) => Eid | undefined;
14
+ //# sourceMappingURL=comp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comp.d.ts","sources":["../comp.ts"],"names":[],"mappings":"AA0BA,cAAc,MAAM,EAAE,IAAI,EAAE,GAAG,2BAAgC;AAC/D,cAAc,QAAQ,2BAAgC;AAItD,yDAAyD,GACzD,OAAO,YAAI,WAAS;AAEpB,qCAAqC,GACrC,OAAO,YAAI,cAAe;AAE1B;;;;CAIC,GACD,OAAO,YAAI,QAAQ,SAAc;AAEjC,oDAAoD,GACpD,OAAO,YAAI,QAAS,GAAG,WAAS,OAAO,SAAS,CAG/C;AAQD;4CAC4C,GAC5C,OAAO,YAAI,UAAW,GAAG,WAAS,MAAM,GAAG,SAAS,CAAkB;AAEtE,gEAAgE,GAChE,OAAO,YAAI,OAAQ,GAAG,SAAS,SAAS,KAAG,MAAM,SAAS,CAAe"}
package/_dist/eid.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { Bundle, Derive, Eid } from "@yaks/graph";
2
+ /**
3
+ * The eid a value lands on: `sha256("<kind>|<value>")` formatted as a UUID
4
+ * (@yaks/graph `derivedEid` — the one derivation every content-addressed
5
+ * component shares, so an id computed here and an id computed elsewhere are the
6
+ * same id).
7
+ *
8
+ * `kind` is the tag component the key carries, not the name a query uses for
9
+ * it: the id is derived from what the entity carries.
10
+ */ export declare let keyEid: (kind: string, value: string) => Eid;
11
+ /**
12
+ * The kind tag a bundle carries, or nothing when it carries none. `tags` is the
13
+ * vocabulary's tag → name map ({@link names}); only a declared kind counts, so
14
+ * an ordinary component stored beside the key is not mistaken for one.
15
+ */ export declare let tagOf: (bundle: Bundle, tags: Record<string, string>) => string | undefined;
16
+ /**
17
+ * How the `key` component derives its own entity's id — the {@link Derive} a
18
+ * graph calls when a key bundle arrives under a `$alias`, so the write that
19
+ * claims a value also learns the id it landed on.
20
+ *
21
+ * A key missing its kind or its value derives nothing (it returns `''`) and the
22
+ * entity takes an ordinary minted id, at which point the {@link stated} hook
23
+ * refuses the write and reports which part was missing — a much better error
24
+ * than a key whose id was derived from half of itself.
25
+ */ export declare let derive: (tags: Record<string, string>) => Derive;
26
+ //# sourceMappingURL=eid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eid.d.ts","sources":["../eid.ts"],"names":[],"mappings":"AAYA,cAAc,MAAM,EAAQ,MAAM,EAAE,GAAG,2BAAgC;AAKvE;;;;;;;;CAQC,GACD,OAAO,YAAI,SAAU,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,IACnB;AAEhC;;;;CAIC,GACD,OAAO,YAAI,QACT,QAAQ,QACR,MAAM,OAAO,MAAM,EAAE,MAAM,MAC1B,MAAM,GAAG,SAAS,CAC0C;AAE/D;;;;;;;;;CASC,GACD,OAAO,YAAI,SACR,MAAM,OAAO,MAAM,EAAE,MAAM,MAAI,OAI/B"}
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from "@yaks/graph";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ /** Derived key ids, over the kinds this vocabulary declares. */ export declare let plugins: (host: {
4
+ vocab: Vocab;
5
+ }) => Plugin[];
6
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAKA,cAAc,MAAM,2BAAgC;AACpD,cAAc,KAAK,2BAAgC;AAGnD,8DAA8D,GAC9D,OAAO,YAAI,UAAW;EAAQ,OAAO;MAAU,SAA8B"}
@@ -0,0 +1,9 @@
1
+ import type { Bundle, Eid, Hook } from "@yaks/graph";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ export declare let gathered: (bundles: Bundle[]) => Map<Eid, Bundle>;
4
+ /**
5
+ * The `mint` hook that refuses an incomplete key, naming what is missing.
6
+ * Registered by {@link https://jsr.io/@yaks/key/doc/~/keys | keys}; exported on
7
+ * its own for a graph that wants the check without the rest.
8
+ */ export declare let stated: (vocab: Vocab) => Hook;
9
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sources":["../guard.ts"],"names":[],"mappings":"AAiBA,cAAc,MAAM,EAAQ,GAAG,EAAE,IAAI,2BAAgC;AAGrE,cAAc,KAAK,2BAAgC;AAMnD,OAAO,YAAI,WAAY,SAAS,aAAW,IAAI,KAAK,QAWnD;AAED;;;;CAIC,GACD,OAAO,YAAI,SAAU,OAAO,UAAQ,KAwBnC"}
@@ -0,0 +1,8 @@
1
+ import type { Keywords } from "@yaks/vocab";
2
+ /** The URI a vocabulary file declares under `$vocabulary` to use `key`. */ export declare let KEY_URI: string;
3
+ /**
4
+ * The `key` keyword vocabulary, ready to register:
5
+ * `loadVocab(docs, [keyKeywords])` carries each component's declaration onto
6
+ * `v.comp(name).keywords.key`, which is where {@link kinds} reads it.
7
+ */ export declare let keyKeywords: Keywords;
8
+ //# sourceMappingURL=keywords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywords.d.ts","sources":["../keywords.ts"],"names":[],"mappings":"AAmBA,cAAc,QAAQ,2BAAgC;AAGtD,yEAAyE,GACzE,OAAO,YAAI,gBAAoC;AAE/C;;;;CAIC,GACD,OAAO,YAAI,aAAa,SAA+C"}
@@ -0,0 +1,14 @@
1
+ import type { Vocab } from "@yaks/vocab";
2
+ /** The component every key carries: the entity it identifies, and the
3
+ * value. */ export declare let KEY: string;
4
+ /**
5
+ * Every kind the vocabulary declares, as name → tag component:
6
+ * `{ alias: 'alias', mailbox: 'email' }`. It reads the `key` keyword, so the
7
+ * vocabulary must have been loaded with `keyKeywords` registered — an
8
+ * unregistered keyword is invisible to the loader.
9
+ */ export declare let kinds: (v: Vocab) => Record<string, string>;
10
+ /**
11
+ * The same declarations the other way round, as tag component → name. This is
12
+ * what reads a key back: a bundle carrying `email` holds a `mailbox` value.
13
+ */ export declare let names: (v: Vocab) => Record<string, string>;
14
+ //# sourceMappingURL=kinds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kinds.d.ts","sources":["../kinds.ts"],"names":[],"mappings":"AAeA,cAAc,KAAK,2BAAgC;AAEnD;UACU,GACV,OAAO,YAAI,YAAW;AAEtB;;;;;CAKC,GACD,OAAO,YAAI,QAAS,GAAG,UAAQ,OAAO,MAAM,EAAE,MAAM,EAQnD;AAED;;;CAGC,GACD,OAAO,YAAI,QAAS,GAAG,UAAQ,OAAO,MAAM,EAAE,MAAM,EAInD"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @yaks/key — the values that identify an entity, stored as entities.
3
+ *
4
+ * A value that identifies something is not a property on the thing it
5
+ * identifies; it is an entity of its own, carrying the `key{of, value}`
6
+ * component and a kind tag component naming what sort of value it is. A store
7
+ * identifies its recipes by a short name (`alias`), a directory its people by
8
+ * address (`email`), a library its books by `isbn`; the structure is the same,
9
+ * and the kinds are yours to declare — this package ships the carrier and the
10
+ * mechanism and not one kind.
11
+ *
12
+ * It is to a has-many value exactly what
13
+ * {@link https://jsr.io/@yaks/edge | @yaks/edge} is to a link: one generic
14
+ * carrier component, tagged by the application's own components, with the
15
+ * entity's id derived from what it holds — so an entity has as many values as
16
+ * you write, writing one twice writes one row, and retiring one means deleting
17
+ * that row.
18
+ *
19
+ * ```ts
20
+ * import { graph } from '@yaks/graph'
21
+ * import { ram } from '@yaks/ram'
22
+ * import { loadVocab } from '@yaks/vocab'
23
+ * import { keyDoc, keyed, keyKeywords, keys } from '@yaks/key'
24
+ *
25
+ * let library = {
26
+ * $defs: {
27
+ * book: { component: true, kind: true, properties: {} },
28
+ * // one component, and `isbn` is a kind of value
29
+ * isbn: { component: true, key: true },
30
+ * },
31
+ * }
32
+ * let vocab = loadVocab([keyDoc, library], [keyKeywords])
33
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [keys(vocab)] })
34
+ * g.apply([
35
+ * { entity: { eid: 'b1' }, book: {} },
36
+ * keyed('isbn', 'b1', '9780441013593'),
37
+ * ])
38
+ * ```
39
+ *
40
+ * Four things follow from that:
41
+ *
42
+ * - **A key's id is derived from the value.** {@link keyEid} hashes the kind
43
+ * and the value, so two writers giving the same value land on one entity, a
44
+ * value is unique within its kind by construction, and reading one back is a
45
+ * `get` rather than a query.
46
+ * - **A key lives only as long as what it identifies.** `of` is a reference
47
+ * declared `death: release`, so deleting a book removes its isbn row and
48
+ * frees the value.
49
+ * - **An incomplete key is refused**, naming what is missing: a key with no
50
+ * kind, no value or no `of` never reaches storage.
51
+ * - **Claiming a value somebody already holds lands on the holder.** A write
52
+ * that mints an entity under a `$alias` and gives it a value another entity
53
+ * already holds patches that entity instead of creating a second one; a
54
+ * caller who wrote an id down rather than using an alias is refused, with the
55
+ * holder named. An explicit deletion of the holder in the same batch permits
56
+ * a transfer, guarded against ownership changing before that batch commits.
57
+ *
58
+ * It imports no platform API, so the same code runs on a server, in a worker,
59
+ * and in a browser tab.
60
+ *
61
+ * @module
62
+ */ export * from "./keywords.js";
63
+ export * from "./kinds.js";
64
+ export * from "./comp.js";
65
+ export * from "./eid.js";
66
+ export * from "./say.js";
67
+ export * from "./guard.js";
68
+ export * from "./resolve.js";
69
+ export * from "./plugin.js";
70
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6DC,GAED,8BAA6B;AAC7B,2BAA0B;AAC1B,0BAAyB;AACzB,yBAAwB;AACxB,yBAAwB;AACxB,2BAA0B;AAC1B,6BAA4B;AAC5B,4BAA2B"}
@@ -0,0 +1,23 @@
1
+ import { type Plugin } from "@yaks/graph/plugin";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ /**
4
+ * The key plugin:
5
+ *
6
+ * ```ts
7
+ * import { loadVocab } from '@yaks/vocab'
8
+ * import { graph } from '@yaks/graph'
9
+ * import { ram } from '@yaks/ram'
10
+ * import { keyDoc, keyKeywords, keys } from '@yaks/key'
11
+ *
12
+ * let isbn = { component: true, key: true }
13
+ * let vocab = loadVocab([keyDoc, { $defs: { isbn } }], [keyKeywords])
14
+ * let g = graph({ storage: ram(vocab), vocab, plugins: [keys(vocab)] })
15
+ * ```
16
+ *
17
+ * It contributes {@link keyDoc}, derives a key's id from the kind and value it
18
+ * holds (so a value written under a `$alias` lands on the same entity every
19
+ * time it is claimed), refuses at `mint` any key missing its kind, its value or
20
+ * its `of`, and resolves a write claiming a value somebody already holds onto
21
+ * that holder.
22
+ */ export declare let keys: (vocab: Vocab) => Plugin;
23
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sources":["../plugin.ts"],"names":[],"mappings":"AASA,SAA0B,KAAK,MAAM,kCAAuC;AAG5E,cAAc,KAAK,2BAAgC;AAenD;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAAI,OAAQ,OAAO,UAAQ,OAUhC"}
@@ -0,0 +1,26 @@
1
+ import type { Eid, Hook, Tx } from "@yaks/graph";
2
+ import type { Vocab } from "@yaks/vocab";
3
+ /**
4
+ * Who holds each of these values in a kind — one `get` for the whole list, with
5
+ * a value nobody holds simply absent from the result. This is the lookup
6
+ * everything else makes: no query, no index, no scan.
7
+ */ export declare let held: (tx: Pick<Tx, 'get'>, kind: string, values: string[]) => Map<string, Eid> | Promise<Map<string, Eid>>;
8
+ /**
9
+ * The `cascade` hook that finishes a release: when the entity a key identified
10
+ * is deleted, the `key` row goes because the vocabulary declares
11
+ * `death: release`, and this removes the kind tag beside it, so no entity is
12
+ * left holding half a key.
13
+ *
14
+ * It is a release and not a cascade on purpose. A cascade would tombstone the
15
+ * key entity, and that id is derived from the value — so the value could never
16
+ * be claimed again, by anyone, for the life of the store. Deleting a recipe
17
+ * must free its name.
18
+ */ export declare let retired: (vocab: Vocab) => Hook;
19
+ /**
20
+ * The `mint` hook that keeps one value on one entity: claiming a value somebody
21
+ * already holds resolves this write's entity onto theirs, and a clash is
22
+ * refused with the holder named. Registered by
23
+ * {@link https://jsr.io/@yaks/key/doc/~/keys | keys}; exported on its own for a
24
+ * graph that wants the behaviour without the rest of the plugin.
25
+ */ export declare let settled: (vocab: Vocab) => Hook;
26
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sources":["../resolve.ts"],"names":[],"mappings":"AA6BA,cAAc,GAAG,EAAE,IAAI,EAAE,EAAE,2BAAgC;AAM3D,cAAc,KAAK,2BAAgC;AAKnD;;;;CAIC,GACD,OAAO,YAAI,OACT,IAAI,KAAK,IAAI,QACb,MAAM,MAAM,EACZ,QAAQ,MAAM,OACb,IAAI,MAAM,EAAE,OAAO,QAAQ,IAAI,MAAM,EAAE,MAYzC;AAED;;;;;;;;;;CAUC,GACD,OAAO,YAAI,UAAW,OAAO,UAAQ,KAepC;AAED;;;;;;CAMC,GACD,OAAO,YAAI,UAAW,OAAO,UAAQ,KAwDpC"}
package/_dist/say.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { Bundle, Eid } from "@yaks/graph";
2
+ /**
3
+ * The bundle that claims a value: `keyed('alias', r, 'lemon-cake')`. `kind` is
4
+ * the tag component the key carries.
5
+ */ export declare let keyed: (kind: string, of: Eid, value: string) => Bundle;
6
+ /**
7
+ * The bundle that gives that value back: both components deleted, the entity
8
+ * left standing so the same value can be claimed again.
9
+ */ export declare let unkeyed: (kind: string, value: string) => Bundle;
10
+ //# sourceMappingURL=say.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"say.d.ts","sources":["../say.ts"],"names":[],"mappings":"AAaA,cAAc,MAAM,EAAE,GAAG,2BAAgC;AAKzD;;;CAGC,GACD,OAAO,YAAI,QAAS,MAAM,MAAM,EAAE,IAAI,KAAK,OAAO,MAAM,KAAG,OAIzD;AAEF;;;CAGC,GACD,OAAO,YAAI,UAAW,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,OAIlD"}
@@ -0,0 +1,9 @@
1
+ import type { Keywords, VocabDoc } from "@yaks/vocab";
2
+ import { keyDoc } from "./comp.js";
3
+ import { keyKeywords } from "./keywords.js";
4
+ export { keyDoc, keyKeywords };
5
+ /** What this package is: its manifest's description, the one place it is
6
+ * written, which a host stamps on each document here. */ export declare let description: string;
7
+ /** Every document this plugin declares. */ export declare let docs: VocabDoc[];
8
+ /** The JSON Schema keywords those documents use. */ export declare let keywords: Keywords[];
9
+ //# sourceMappingURL=vocab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,EAAE,QAAQ,2BAAgC;AAChE,SAAS,MAAM,oBAAmB;AAClC,SAAS,WAAW,wBAAuB;AAG3C,SAAS,MAAM,EAAE,WAAW,GAAE;AAE9B;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAqB;AAEtC,kDAAkD,GAClD,OAAO,YAAI,UAAU,WAA0B"}
package/comp.js ADDED
@@ -0,0 +1,49 @@
1
+ // The one component this package ships: `key{of, value}`.
2
+ //
3
+ // It is to a has-many VALUE what `edge{from, to}` is to a link. An entity does
4
+ // not hold its identifying values in a property; each value is a key entity of
5
+ // its own — `key{of, value}` plus a kind tag component naming which kind of
6
+ // value it is — so a recipe is identified by both `lemon-cake` and
7
+ // `recipe:2019-07` because two rows point at it, adding one is a write, and
8
+ // retiring one means deleting that row. A list property would have been the
9
+ // other design and it is the worse one: every write would be a
10
+ // read-modify-write of somebody else's property, and two writers adding a value
11
+ // at once would lose one.
12
+ //
13
+ // `of` is a reference declared `death: release`, which is the whole of a key's
14
+ // lifecycle: a value for a deleted thing identifies nothing, and the row is
15
+ // removed rather than the entity, so the value can be claimed again.
16
+ //
17
+ // The value is unique within its kind, and nothing declares that — the key's
18
+ // own id is `sha256("<tag>|<value>")` (./eid.ts), so two writers giving the
19
+ // same value in the same kind land on one row by construction. A `unique` on
20
+ // the property would have been wrong anyway: two kinds may hold the same
21
+ // string, and only the pair is the constraint.
22
+ //
23
+ // The document itself is `./vocab.json` — plain JSON Schema, readable by
24
+ // anything that reads JSON. This file re-exports it under the name callers
25
+ // import and holds the explanation of why it is shaped the way it is.
26
+ import doc from './vocab.json' with {
27
+ type: 'json'
28
+ };
29
+ import { KEY } from "./kinds.js";
30
+ /** The property naming the entity the value identifies. */ export let OF = 'of';
31
+ /** The property carrying the value. */ export let VALUE = 'value';
32
+ /**
33
+ * The `key` component as a vocabulary document, to load beside your own:
34
+ * `loadVocab([keyDoc, ...mine], [keyKeywords])`. The kind tags are yours to
35
+ * declare — this document is only the carrier.
36
+ */ export let keyDoc = doc;
37
+ /** The `key` component in a bundle, if it has one. */ export let keyOf = (b)=>{
38
+ let comp = b[KEY];
39
+ return comp && typeof comp == 'object' ? comp : undefined;
40
+ };
41
+ // One property of a bundle's key, as a non-empty string, or nothing.
42
+ let said = (b, prop)=>{
43
+ let v = b && keyOf(b)?.[prop];
44
+ return typeof v == 'string' && v ? v : undefined;
45
+ };
46
+ /** The value in a bundle's key. An absent component, a cleared one and an
47
+ * empty string all mean there is no value. */ export let valueOf = (b)=>said(b, VALUE);
48
+ /** The entity a bundle's key identifies, if it identifies one. */ export let ofOf = (b)=>said(b, OF);
49
+ //# sourceMappingURL=comp.js.map
package/comp.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comp.js","sources":["./comp.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,4EAA4E;AAC5E,mEAAmE;AACnE,4EAA4E;AAC5E,4EAA4E;AAC5E,+DAA+D;AAC/D,gFAAgF;AAChF,0BAA0B;AAC1B,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,qEAAqE;AACrE,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,yEAAyE;AACzE,+CAA+C;AAC/C,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,sEAAsE;AAItE,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AACpD,SAAS,GAAG,qBAAoB;AAEhC,yDAAyD,GACzD,OAAO,IAAI,KAAK,KAAI;AAEpB,qCAAqC,GACrC,OAAO,IAAI,QAAQ,QAAO;AAE1B;;;;CAIC,GACD,OAAO,IAAI,SAAmB,IAAG;AAEjC,oDAAoD,GACpD,OAAO,IAAI,QAAQ,CAAC;EAClB,IAAI,OAAO,CAAC,CAAC,IAAI;EACjB,OAAO,QAAQ,OAAO,QAAQ,WAAW,OAAe;AAC1D,EAAC;AAED,qEAAqE;AACrE,IAAI,OAAO,CAAC,GAAuB;EACjC,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,KAAK;EAC7B,OAAO,OAAO,KAAK,YAAY,IAAI,IAAI;AACzC;AAEA;4CAC4C,GAC5C,OAAO,IAAI,UAAU,CAAC,IAAkC,KAAK,GAAG,OAAM;AAEtE,gEAAgE,GAChE,OAAO,IAAI,OAAO,CAAC,IAA2C,KAAK,GAAG,IAAG"}