@antelopejs/interface-database-decorators 0.1.6 → 0.1.8

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 (63) hide show
  1. package/README.md +0 -2
  2. package/dist/antelope.test.js +4 -3
  3. package/dist/antelope.test.js.map +1 -1
  4. package/dist/common.d.ts +7 -1
  5. package/dist/common.js +10 -2
  6. package/dist/common.js.map +1 -1
  7. package/dist/database.d.ts +2 -1
  8. package/dist/database.js +20 -9
  9. package/dist/database.js.map +1 -1
  10. package/dist/model.d.ts +7 -2
  11. package/dist/model.js +25 -13
  12. package/dist/model.js.map +1 -1
  13. package/dist/modifiers/autodate.js.map +1 -1
  14. package/dist/modifiers/common.js +2 -2
  15. package/dist/modifiers/common.js.map +1 -1
  16. package/dist/modifiers/encryption.js +1 -1
  17. package/dist/modifiers/encryption.js.map +1 -1
  18. package/dist/modifiers/hash.js +1 -1
  19. package/dist/modifiers/hash.js.map +1 -1
  20. package/dist/modifiers/localization.js.map +1 -1
  21. package/dist/relation.js +1 -1
  22. package/dist/relation.js.map +1 -1
  23. package/dist/schema.js +2 -0
  24. package/dist/schema.js.map +1 -1
  25. package/dist/table.d.ts +39 -5
  26. package/dist/table.js +35 -8
  27. package/dist/table.js.map +1 -1
  28. package/dist/tests/common.test.js +1 -1
  29. package/dist/tests/common.test.js.map +1 -1
  30. package/dist/tests/cross_instance.test.d.ts +1 -0
  31. package/dist/tests/cross_instance.test.js +120 -0
  32. package/dist/tests/cross_instance.test.js.map +1 -0
  33. package/dist/tests/database.test.js +98 -2
  34. package/dist/tests/database.test.js.map +1 -1
  35. package/dist/tests/helpers/other-instance.d.ts +13 -0
  36. package/dist/tests/helpers/other-instance.js +46 -0
  37. package/dist/tests/helpers/other-instance.js.map +1 -0
  38. package/dist/tests/integration.test.js +4 -4
  39. package/dist/tests/integration.test.js.map +1 -1
  40. package/dist/tests/model.test.js +4 -4
  41. package/dist/tests/model.test.js.map +1 -1
  42. package/dist/tests/modifiers/autodate.test.js +3 -3
  43. package/dist/tests/modifiers/autodate.test.js.map +1 -1
  44. package/dist/tests/modifiers/common.test.js +2 -2
  45. package/dist/tests/modifiers/common.test.js.map +1 -1
  46. package/dist/tests/modifiers/encryption.test.js +2 -2
  47. package/dist/tests/modifiers/encryption.test.js.map +1 -1
  48. package/dist/tests/modifiers/hash.test.js +2 -2
  49. package/dist/tests/modifiers/hash.test.js.map +1 -1
  50. package/dist/tests/modifiers/localization.test.js +2 -2
  51. package/dist/tests/modifiers/localization.test.js.map +1 -1
  52. package/dist/tests/relation.test.js +2 -2
  53. package/dist/tests/relation.test.js.map +1 -1
  54. package/dist/tests/schema.test.js +2 -2
  55. package/dist/tests/schema.test.js.map +1 -1
  56. package/dist/tests/table.test.js +11 -11
  57. package/dist/tests/table.test.js.map +1 -1
  58. package/docs/2.table-definitions.md +90 -18
  59. package/docs/3.table-modifiers.md +77 -23
  60. package/docs/4.data-models.md +5 -5
  61. package/docs/5.parameter-decoration.md +14 -3
  62. package/package.json +66 -57
  63. package/skills/database-decorators-interface/SKILL.md +61 -16
@@ -15,17 +15,50 @@ Peer interfaces required: `@antelopejs/interface-core`, `@antelopejs/interface-a
15
15
  ## Imports
16
16
 
17
17
  ```typescript
18
- import { Table, Field, Index, Fixture } from "@antelopejs/interface-database-decorators/table";
19
- import { RegisterTable, getTablesForSchema } from "@antelopejs/interface-database-decorators/schema";
18
+ import {
19
+ Table,
20
+ Field,
21
+ Index,
22
+ Fixture,
23
+ } from "@antelopejs/interface-database-decorators/table";
24
+ import {
25
+ RegisterTable,
26
+ getTablesForSchema,
27
+ } from "@antelopejs/interface-database-decorators/schema";
20
28
  import { RegisterSchema } from "@antelopejs/interface-database-decorators/database";
21
- import { BasicDataModel, GetModel, Model } from "@antelopejs/interface-database-decorators/model";
29
+ import {
30
+ BasicDataModel,
31
+ GetModel,
32
+ Model,
33
+ } from "@antelopejs/interface-database-decorators/model";
22
34
  import { Relation } from "@antelopejs/interface-database-decorators/relation";
23
- import { DatumStaticMetadata, getMetadata } from "@antelopejs/interface-database-decorators/common";
24
- import { CreationTime, UpdateTime } from "@antelopejs/interface-database-decorators/modifiers/autodate";
25
- import { Encrypted, EncryptionModifier } from "@antelopejs/interface-database-decorators/modifiers/encryption";
26
- import { Hashed, HashModifier } from "@antelopejs/interface-database-decorators/modifiers/hash";
27
- import { Localized, LocalizationModifier } from "@antelopejs/interface-database-decorators/modifiers/localization";
28
- import { Modifier, OneWayModifier, TwoWayModifier, attachModifier, toPlainData } from "@antelopejs/interface-database-decorators/modifiers/common";
35
+ import {
36
+ DatumStaticMetadata,
37
+ getMetadata,
38
+ } from "@antelopejs/interface-database-decorators/common";
39
+ import {
40
+ CreationTime,
41
+ UpdateTime,
42
+ } from "@antelopejs/interface-database-decorators/modifiers/autodate";
43
+ import {
44
+ Encrypted,
45
+ EncryptionModifier,
46
+ } from "@antelopejs/interface-database-decorators/modifiers/encryption";
47
+ import {
48
+ Hashed,
49
+ HashModifier,
50
+ } from "@antelopejs/interface-database-decorators/modifiers/hash";
51
+ import {
52
+ Localized,
53
+ LocalizationModifier,
54
+ } from "@antelopejs/interface-database-decorators/modifiers/localization";
55
+ import {
56
+ Modifier,
57
+ OneWayModifier,
58
+ TwoWayModifier,
59
+ attachModifier,
60
+ toPlainData,
61
+ } from "@antelopejs/interface-database-decorators/modifiers/common";
29
62
  ```
30
63
 
31
64
  The package root re-exports everything above and also imports `reflect-metadata` (see gotchas).
@@ -36,7 +69,8 @@ The package root re-exports everything above and also imports `reflect-metadata`
36
69
  @RegisterTable("recipes", "cookbook") // (tableName, schemaName)
37
70
  class Recipe extends Table {
38
71
  // _id: string is inherited as the primary key
39
- @Index() @Field("string")
72
+ @Index()
73
+ @Field("string")
40
74
  declare slug: string;
41
75
  @Field("string")
42
76
  declare tagline: string;
@@ -46,7 +80,10 @@ const RecipeModel = BasicDataModel(Recipe); // table name taken from @RegisterTa
46
80
  await RegisterSchema("cookbook"); // once at startup: provisions all tables registered for "cookbook", runs fixtures
47
81
 
48
82
  const recipes = GetModel(RecipeModel); // cached per (model class, instanceId)
49
- await recipes.insert({ slug: "grilled-halloumi", tagline: "Smoky skewers" }, { validate: true });
83
+ await recipes.insert(
84
+ { slug: "grilled-halloumi", tagline: "Smoky skewers" },
85
+ { validate: true },
86
+ );
50
87
  const bySlug = await recipes.getBy("slug", "grilled-halloumi");
51
88
  const one = await recipes.get(bySlug[0]._id);
52
89
  await recipes.update(one._id, { tagline: "Smoky halloumi skewers" });
@@ -68,12 +105,16 @@ class RecipesController extends Controller("/recipes") {
68
105
  ## Field modifiers
69
106
 
70
107
  ```typescript
71
- class Chef extends Table.with(HashModifier, EncryptionModifier, LocalizationModifier) {
72
- @Hashed() declare passphrase: string; // one-way; test via instance.testHash("passphrase", value)
108
+ class Chef extends Table.with(
109
+ HashModifier,
110
+ EncryptionModifier,
111
+ LocalizationModifier,
112
+ ) {
113
+ @Hashed() declare passphrase: string; // one-way; test via instance.testHash("passphrase", value)
73
114
  @Encrypted({ secretKey }) declare supplierCode: string; // transparent encrypt/decrypt (autolock + autounlock)
74
- @Localized() declare motto: string; // read AND write via instance.localize("en", ["motto"])
75
- @CreationTime() declare hiredAt: Date; // set on insert, stripped from updates
76
- @UpdateTime() declare lastActiveAt: Date; // refreshed on insert and update
115
+ @Localized() declare motto: string; // read AND write via instance.localize("en", ["motto"])
116
+ @CreationTime() declare hiredAt: Date; // set on insert, stripped from updates
117
+ @UpdateTime() declare lastActiveAt: Date; // refreshed on insert and update
77
118
  }
78
119
  ```
79
120
 
@@ -91,8 +132,12 @@ class Chef extends Table.with(HashModifier, EncryptionModifier, LocalizationModi
91
132
  io-ts-style codec with `.decode`; plain string field tokens are skipped. Update validates with
92
133
  `{ partial: true }` semantics.
93
134
  - `update(obj)` without an explicit id asserts that the object carries the primary key (`_id` by default).
135
+ - Indexes are scoped to the schema instance. Add `@Index({ crossInstance: true })` only for indexes also queried
136
+ across all instances (`CROSS_INSTANCE`); it never changes results, only speed. On a group, one member setting it
137
+ applies it to the whole group.
94
138
  - `@Fixture` data is only inserted by `RegisterSchema` when the table is empty (count === 0).
95
139
  - `GetModel` caches by model class + instanceId; the same pair always returns the same instance.
140
+ - `RegisterSchema` binds each registered table class to the `Schema` it builds; call it in the module that declares the tables. `User.table()`, `User.table(instanceId)` and `User.table(db)` then return the class's AQL table, and `GetModel` builds `BasicDataModel` models on that same schema, even when another module (bound to another database) calls them. An unbound class throws rather than looking a schema up by id.
96
141
  - Serialization of modified instances to plain JSON goes through `toPlainData` (auto-attached as `toJSON`).
97
142
 
98
143
  Deeper reference: this package's `docs/` chapters — Introduction, Table Definitions, Table Modifiers,