@fireproof/core-test 0.23.1 → 0.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/blockstore/interceptor-gateway.test.js.map +1 -1
  2. package/blockstore/keyed-crypto-indexeddb-file.test.js.map +1 -1
  3. package/blockstore/keyed-crypto.test.js.map +1 -1
  4. package/blockstore/loader.test.js.map +1 -1
  5. package/blockstore/standalone.test.js.map +1 -1
  6. package/blockstore/store.test.js.map +1 -1
  7. package/blockstore/transaction.test.js.map +1 -1
  8. package/fireproof/all-gateway.test.js.map +1 -1
  9. package/fireproof/attachable.test.js.map +1 -1
  10. package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js.map +1 -1
  11. package/fireproof/charwise-boolean.test.js.map +1 -1
  12. package/fireproof/compact-strategy.test.js.map +1 -1
  13. package/fireproof/concurrent.test.js.map +1 -1
  14. package/fireproof/crdt.test.js.map +1 -1
  15. package/fireproof/database.test.js.map +1 -1
  16. package/fireproof/deleted-docs-handling.test.js.map +1 -1
  17. package/fireproof/fireproof.test.fixture.js.map +1 -1
  18. package/fireproof/fireproof.test.js.map +1 -1
  19. package/fireproof/hello.test.js.map +1 -1
  20. package/fireproof/indexer.test.js.map +1 -1
  21. package/fireproof/multiple-ledger.test.js.map +1 -1
  22. package/fireproof/query-docs.test.js.map +1 -1
  23. package/fireproof/query-limit-issue.test.js.map +1 -1
  24. package/fireproof/query-property-inconsistency.test.js.map +1 -1
  25. package/fireproof/query-result-properties.test.js.map +1 -1
  26. package/fireproof/stable-cid.test.js.map +1 -1
  27. package/fireproof/utils.test.js.map +1 -1
  28. package/gateway/file/loader-config.test.js.map +1 -1
  29. package/gateway/indexeddb/create-db-on-write.test.js.map +1 -1
  30. package/gateway/indexeddb/loader-config.test.js.map +1 -1
  31. package/global-setup.js.map +1 -1
  32. package/helpers.js.map +1 -1
  33. package/package.json +18 -18
  34. package/protocols/cloud/msger.test.js.map +1 -1
  35. package/runtime/fp-envelope-serialize.test.js.map +1 -1
  36. package/runtime/key-bag.test.js.map +1 -1
  37. package/runtime/meta-key-hack.test.js.map +1 -1
  38. package/setup.file.js.map +1 -1
  39. package/setup.indexeddb.js.map +1 -1
  40. package/setup.memory.js.map +1 -1
  41. package/vitest.config.js.map +1 -1
  42. package/vitest.file.config.js.map +1 -1
  43. package/vitest.indexeddb.config.js.map +1 -1
  44. package/vitest.memory.config.js.map +1 -1
  45. package/blockstore/fp-envelope.test.ts-off +0 -65
  46. package/blockstore/fragment-gateway.test.ts-off +0 -106
  47. package/blockstore/interceptor-gateway.test.ts +0 -259
  48. package/blockstore/keyed-crypto-indexeddb-file.test.ts +0 -134
  49. package/blockstore/keyed-crypto.test.ts +0 -381
  50. package/blockstore/loader.test.ts +0 -313
  51. package/blockstore/standalone.test.ts +0 -156
  52. package/blockstore/store.test.ts +0 -199
  53. package/blockstore/transaction.test.ts +0 -132
  54. package/fireproof/all-gateway.test.ts +0 -477
  55. package/fireproof/attachable.test.ts +0 -677
  56. package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.car +0 -0
  57. package/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +0 -324
  58. package/fireproof/charwise-boolean.test.ts +0 -68
  59. package/fireproof/compact-strategy.test.ts +0 -40
  60. package/fireproof/concurrent.test.ts +0 -37
  61. package/fireproof/crdt.test.ts +0 -572
  62. package/fireproof/database.test.ts +0 -772
  63. package/fireproof/deleted-docs-handling.test.ts +0 -112
  64. package/fireproof/fireproof.test.fixture.ts +0 -133
  65. package/fireproof/fireproof.test.ts +0 -767
  66. package/fireproof/hello.test.ts +0 -75
  67. package/fireproof/indexer.test.ts +0 -459
  68. package/fireproof/multiple-ledger.test.ts +0 -67
  69. package/fireproof/query-docs.test.ts +0 -117
  70. package/fireproof/query-limit-issue.test.ts +0 -147
  71. package/fireproof/query-property-inconsistency.test.ts +0 -90
  72. package/fireproof/query-result-properties.test.ts +0 -43
  73. package/fireproof/stable-cid.test.ts +0 -72
  74. package/fireproof/utils.test.ts +0 -137
  75. package/gateway/file/loader-config.test.ts +0 -309
  76. package/gateway/indexeddb/create-db-on-write.test.ts +0 -202
  77. package/gateway/indexeddb/loader-config.test.ts +0 -80
  78. package/global-setup.ts +0 -11
  79. package/helpers.ts +0 -177
  80. package/protocols/cloud/msger.test.ts +0 -559
  81. package/runtime/fp-envelope-serialize.test.ts +0 -266
  82. package/runtime/key-bag.test.ts +0 -243
  83. package/runtime/meta-key-hack.test.ts +0 -103
  84. package/setup.file.ts +0 -1
  85. package/setup.indexeddb.ts +0 -0
  86. package/setup.memory.ts +0 -2
  87. package/tsconfig.json +0 -18
  88. package/vitest.config.ts +0 -8
  89. package/vitest.file.config.ts +0 -11
  90. package/vitest.indexeddb.config.ts +0 -34
  91. package/vitest.memory.config.ts +0 -24
@@ -1,117 +0,0 @@
1
- import { Database, DocWithId, fireproof } from "@fireproof/core";
2
- import { describe, beforeEach, afterEach, it, expect } from "vitest";
3
-
4
- interface TestDoc {
5
- text: string;
6
- category: string;
7
- active: boolean;
8
- }
9
-
10
- describe("query return value consistency", function () {
11
- let db: Database;
12
-
13
- beforeEach(async () => {
14
- db = fireproof("test-query-docs");
15
-
16
- // Add test documents
17
- await db.put({ _id: "doc1", text: "hello world", category: "greeting", active: true });
18
- await db.put({ _id: "doc2", text: "goodbye world", category: "farewell", active: true });
19
- await db.put({ _id: "doc3", text: "hello again", category: "greeting", active: false });
20
- });
21
-
22
- afterEach(async () => {
23
- await db.close();
24
- await db.destroy();
25
- });
26
-
27
- it("database query should return docs property like useLiveQuery", async function () {
28
- // This test should initially fail because the query method doesn't return docs yet
29
- const result = await db.query<TestDoc>("category");
30
-
31
- // Check that rows property exists (this should pass)
32
- expect(result).toHaveProperty("rows");
33
- expect(result.rows.length).toBe(3);
34
-
35
- // Check that docs property exists (this should fail until we implement the feature)
36
- expect(result).toHaveProperty("docs");
37
- expect(Array.isArray(result.docs)).toBe(true);
38
- expect(result.docs.length).toBe(3);
39
-
40
- // Verify docs contain the correct document data
41
- const docIds = result.docs.map((doc) => doc._id).sort();
42
- expect(docIds).toEqual(["doc1", "doc2", "doc3"]);
43
- });
44
-
45
- it("should return docs with the same order as rows", async function () {
46
- const result = await db.query<TestDoc>("category");
47
-
48
- // Ensure docs array exists
49
- expect(result).toHaveProperty("docs");
50
-
51
- // Verify the order matches between rows and docs
52
- for (let i = 0; i < result.rows.length; i++) {
53
- const row = result.rows[i];
54
- const doc = result.docs[i];
55
- expect(doc._id).toBe(row.id);
56
- }
57
- });
58
-
59
- it("should work with complex map functions and query options", async function () {
60
- // Test with a map function and query options
61
- const result = await db.query<TestDoc, boolean>((doc) => doc.active, {
62
- key: true,
63
- includeDocs: true,
64
- });
65
-
66
- // Check rows (this should pass)
67
- expect(result.rows.length).toBeGreaterThan(0);
68
-
69
- // Check docs property (this should fail until we implement the feature)
70
- expect(result).toHaveProperty("docs");
71
- expect(result.docs.length).toBe(result.rows.length);
72
-
73
- // Verify all returned docs are active
74
- result.docs.forEach((doc) => {
75
- // Since we know these are TestDoc documents
76
- expect((doc as DocWithId<TestDoc>).active).toBe(true);
77
- });
78
- });
79
-
80
- it("should only return docs with false value when queried with {key: false}", async function () {
81
- // Test with a map function and query options for false value
82
- const result = await db.query<TestDoc, boolean>((doc) => doc.active, {
83
- key: false,
84
- includeDocs: true,
85
- });
86
-
87
- // Should only return documents where active is false
88
- expect(result.rows.length).toBe(1); // We only have one document with active: false
89
-
90
- // Check docs property exists and matches rows length
91
- expect(result).toHaveProperty("docs");
92
- expect(result.docs.length).toBe(result.rows.length);
93
-
94
- // Verify all returned docs have active set to false
95
- result.docs.forEach((doc) => {
96
- expect((doc as DocWithId<TestDoc>).active).toBe(false);
97
- });
98
-
99
- // Make sure no documents with active: true are included
100
- const activeTrue = result.docs.filter((doc) => (doc as DocWithId<TestDoc>).active === true);
101
- expect(activeTrue.length).toBe(0); // No active: true docs should be included
102
-
103
- // Now run a query with key: true for comparison
104
- const trueResult = await db.query<TestDoc, boolean>((doc) => doc.active, {
105
- key: true,
106
- includeDocs: true,
107
- });
108
-
109
- // This correctly returns only active: true documents
110
- expect(trueResult.rows.length).toBe(2);
111
-
112
- // All returned docs have active set to true
113
- trueResult.docs.forEach((doc) => {
114
- expect((doc as DocWithId<TestDoc>).active).toBe(true);
115
- });
116
- });
117
- });
@@ -1,147 +0,0 @@
1
- import { describe, it, beforeEach, afterEach, expect } from "vitest";
2
- import { Database, fireproof } from "@fireproof/core";
3
-
4
- interface TodoDoc {
5
- task: string;
6
- completed: boolean;
7
- priority?: number;
8
- }
9
-
10
- describe("query limit handling", () => {
11
- let db: Database;
12
-
13
- beforeEach(async () => {
14
- db = await fireproof("test-query-limit");
15
-
16
- // Create multiple documents with different completed values and priorities
17
- await db.put({ _id: "task1", task: "Task 1", completed: true, priority: 1 });
18
- await db.put({ _id: "task2", task: "Task 2", completed: true, priority: 2 });
19
- await db.put({ _id: "task3", task: "Task 3", completed: false, priority: 3 });
20
- await db.put({ _id: "task4", task: "Task 4", completed: false, priority: 4 });
21
- await db.put({ _id: "task5", task: "Task 5", completed: true, priority: 5 });
22
- });
23
-
24
- afterEach(async () => {
25
- await db.destroy();
26
- });
27
-
28
- // PASSING CASES - These should work correctly with the current implementation
29
-
30
- it("should correctly limit results for regular queries", async () => {
31
- // Regular query with limit (no key/keys specified)
32
- const queryResult = await db.query("completed", {
33
- includeDocs: false,
34
- limit: 2,
35
- });
36
-
37
- // This should pass - limit should work for regular queries
38
- expect(queryResult.rows.length).toBe(2);
39
- });
40
-
41
- it("should correctly limit results for 'key' parameter queries", async () => {
42
- // Query with a single key and limit
43
- const queryResult = await db.query("completed", {
44
- key: true,
45
- includeDocs: false,
46
- limit: 2,
47
- });
48
-
49
- // This should pass - limit should work for queries with 'key' option
50
- expect(queryResult.rows.length).toBe(2);
51
-
52
- // All results should have completed=true
53
- queryResult.rows.forEach((row) => {
54
- expect(row.key).toBe(true);
55
- });
56
- });
57
-
58
- it("should correctly limit range query results", async () => {
59
- // Query with range and limit
60
- const queryResult = await db.query("priority", {
61
- range: [2, 4],
62
- includeDocs: false,
63
- limit: 2,
64
- });
65
-
66
- // This should pass - limit should work for range queries
67
- expect(queryResult.rows.length).toBe(2);
68
-
69
- // All results should have priority between 2 and 4
70
- queryResult.rows.forEach((row) => {
71
- expect(row.key).toBeGreaterThanOrEqual(2);
72
- expect(row.key).toBeLessThanOrEqual(4);
73
- });
74
- });
75
-
76
- // FAILING CASES - These demonstrate the current bug
77
-
78
- it("should respect the limit option with 'keys' parameter (currently failing)", async () => {
79
- // Query with multiple keys and limit=1
80
- // This should return only 1 result total, but currently returns 1 per key
81
- const queryResult = await db.query("completed", {
82
- keys: [true, false],
83
- includeDocs: false,
84
- limit: 1,
85
- });
86
-
87
- // This assertion will fail with the current implementation
88
- // Current behavior: Returns limit=1 for EACH key, so 2 results total
89
- // Expected behavior: Returns limit=1 across ALL keys combined
90
- expect(queryResult.rows.length).toBe(1);
91
- });
92
-
93
- it("should apply limit correctly to combined results from multiple keys", async () => {
94
- // Query with multiple keys and limit=3
95
- // Should return exactly 3 results total
96
- const queryResult = await db.query<TodoDoc, boolean>("completed", {
97
- keys: [true, false],
98
- includeDocs: false,
99
- limit: 3,
100
- });
101
-
102
- // This assertion verifies that limit is applied to the combined result
103
- expect(queryResult.rows.length).toBe(3);
104
- });
105
-
106
- it("demonstrates the limit+1 issue with the 'keys' parameter", async () => {
107
- // Create a controlled test case with exact document counts
108
- await db.destroy();
109
- db = await fireproof("test-exact-limit");
110
-
111
- // Create exactly 2 documents with completed=true and 2 with completed=false
112
- await db.put({ _id: "doc1", task: "Doc 1", completed: true });
113
- await db.put({ _id: "doc2", task: "Doc 2", completed: true });
114
- await db.put({ _id: "doc3", task: "Doc 3", completed: false });
115
- await db.put({ _id: "doc4", task: "Doc 4", completed: false });
116
-
117
- // Query with limit=1 - should return exactly 1 result total
118
- const result1 = await db.query("completed", {
119
- keys: [true, false],
120
- limit: 1,
121
- includeDocs: false,
122
- });
123
-
124
- // Will fail - returns 2 instead of 1
125
- expect(result1.rows.length).toBe(1);
126
-
127
- // Query with limit=2 - should return exactly 2 results total
128
- const result2 = await db.query("completed", {
129
- keys: [true, false],
130
- limit: 2,
131
- includeDocs: false,
132
- });
133
-
134
- // Will fail - returns 4 instead of 2
135
- expect(result2.rows.length).toBe(2);
136
-
137
- // Query with limit=3 - should return exactly 3 results total
138
- const result3 = await db.query("completed", {
139
- keys: [true, false],
140
- limit: 3,
141
- includeDocs: false,
142
- });
143
-
144
- // Will fail - returns 4 instead of 3
145
- expect(result3.rows.length).toBe(3);
146
- });
147
- });
@@ -1,90 +0,0 @@
1
- import { Database, fireproof } from "@fireproof/core";
2
- import { describe, beforeEach, afterEach, it, expect } from "vitest";
3
-
4
- interface TestDoc {
5
- text: string;
6
- category: string;
7
- count: number;
8
- }
9
-
10
- describe("query property inconsistency issue", function () {
11
- let db: Database;
12
-
13
- beforeEach(async () => {
14
- db = fireproof("test-query-property-inconsistency");
15
-
16
- // Add test documents
17
- await db.put({ _id: "doc1", text: "hello world", category: "greeting", count: 1 });
18
- await db.put({ _id: "doc2", text: "goodbye world", category: "farewell", count: 2 });
19
- await db.put({ _id: "doc3", text: "hello again", category: "greeting", count: 3 });
20
- });
21
-
22
- afterEach(async () => {
23
- await db.close();
24
- await db.destroy();
25
- });
26
-
27
- it("demonstrates property inconsistency in query results", async function () {
28
- // Case 1: Query without key option - should have 'value' property
29
- const queryNoKey = await db.query<TestDoc>((doc) => doc.category);
30
-
31
- // Verify it has 'value' property
32
- expect(queryNoKey.rows[0]).toHaveProperty("value");
33
-
34
- // Case 2: Query with key option - currently has 'row' property instead of 'value'
35
- const queryWithKey = await db.query<TestDoc>((doc) => doc.category, {
36
- key: "greeting",
37
- });
38
-
39
- // THIS WILL FAIL - Demonstrating the inconsistency
40
- // After standardizing on 'value', this assertion should pass
41
- expect(queryWithKey.rows[0]).toHaveProperty("value");
42
-
43
- // This assertion will pass after standardizing on 'value' and removing 'row'
44
- expect(queryWithKey.rows[0]).not.toHaveProperty("row");
45
- });
46
-
47
- it("should use consistent property names regardless of query type", async function () {
48
- // Multiple query variations to test different code paths
49
-
50
- // 1. Regular query (no options)
51
- const regularQuery = await db.query<TestDoc>((doc) => doc.category);
52
-
53
- // 2. Query with key option
54
- const keyQuery = await db.query<TestDoc>((doc) => doc.category, {
55
- key: "greeting",
56
- });
57
-
58
- // 3. Query with range option
59
- const rangeQuery = await db.query<TestDoc>((doc) => doc.count, {
60
- range: [1, 3],
61
- });
62
-
63
- // 4. Query with prefix option
64
- const prefixQuery = await db.query<TestDoc>((doc) => [doc.category, doc.count], {
65
- prefix: ["greeting"],
66
- });
67
-
68
- // Check each query type has the 'value' property
69
- expect(regularQuery.rows[0]).toHaveProperty("value");
70
- expect(keyQuery.rows[0]).toHaveProperty("value");
71
- expect(rangeQuery.rows[0]).toHaveProperty("value");
72
- expect(prefixQuery.rows[0]).toHaveProperty("value");
73
-
74
- // Ensure no query has the 'row' property
75
- expect(regularQuery.rows[0]).not.toHaveProperty("row");
76
- expect(keyQuery.rows[0]).not.toHaveProperty("row");
77
- expect(rangeQuery.rows[0]).not.toHaveProperty("row");
78
- expect(prefixQuery.rows[0]).not.toHaveProperty("row");
79
-
80
- // Ensure all queries have the same set of properties
81
- const regularProps = Object.keys(regularQuery.rows[0]).sort();
82
- const keyProps = Object.keys(keyQuery.rows[0]).sort();
83
- const rangeProps = Object.keys(rangeQuery.rows[0]).sort();
84
- const prefixProps = Object.keys(prefixQuery.rows[0]).sort();
85
-
86
- expect(keyProps).toEqual(regularProps);
87
- expect(rangeProps).toEqual(regularProps);
88
- expect(prefixProps).toEqual(regularProps);
89
- });
90
- });
@@ -1,43 +0,0 @@
1
- import { Database, fireproof } from "@fireproof/core";
2
- import { describe, beforeEach, afterEach, it, expect } from "vitest";
3
-
4
- interface TestDoc {
5
- text: string;
6
- category: string;
7
- count: number;
8
- }
9
-
10
- describe("query result property consistency", function () {
11
- let db: Database;
12
-
13
- beforeEach(async () => {
14
- db = fireproof("test-query-result-properties");
15
-
16
- // Add test documents
17
- await db.put({ _id: "doc1", text: "hello world", category: "greeting", count: 1 });
18
- await db.put({ _id: "doc2", text: "goodbye world", category: "farewell", count: 2 });
19
- await db.put({ _id: "doc3", text: "hello again", category: "greeting", count: 3 });
20
- });
21
-
22
- afterEach(async () => {
23
- await db.close();
24
- await db.destroy();
25
- });
26
-
27
- it("should have consistent result properties regardless of query options", async function () {
28
- // Query without using the key option
29
- const resultWithoutKey = await db.query<TestDoc>((doc) => doc.category);
30
-
31
- // Query with the key option
32
- const resultWithKey = await db.query<TestDoc>((doc) => doc.category, {
33
- key: "greeting",
34
- });
35
-
36
- // Add assertions to check property existence
37
- const withoutKeyProps = Object.keys(resultWithoutKey.rows[0]);
38
- const withKeyProps = Object.keys(resultWithKey.rows[0]);
39
-
40
- // Test if the properties are the same in both cases
41
- expect(withoutKeyProps).toEqual(withKeyProps);
42
- });
43
- });
@@ -1,72 +0,0 @@
1
- import { sha256 } from "multiformats/hashes/sha2";
2
- import { base58btc } from "multiformats/bases/base58";
3
- import { URI, toCryptoRuntime } from "@adviser/cement";
4
- import * as cborg from "cborg";
5
- import { asyncBlockDecode, asyncBlockEncode, ensureSuperThis, keyedCryptoFactory } from "@fireproof/core-runtime";
6
- import { describe, beforeEach, it, expect } from "vitest";
7
- import { getKeyBag } from "@fireproof/core-keybag";
8
- import { CryptoAction, IvKeyIdData } from "@fireproof/core-types-blockstore";
9
-
10
- const sthis = ensureSuperThis();
11
- describe.each([
12
- async () => {
13
- const kb = await getKeyBag(sthis, {});
14
- const keyStr = base58btc.encode(toCryptoRuntime().randomBytes(kb.rt.keyLength));
15
- return await keyedCryptoFactory(URI.from(`test://bla?storekey=${keyStr}`), kb, sthis);
16
- },
17
- async () => {
18
- const kb = await getKeyBag(sthis, {});
19
- return await keyedCryptoFactory(URI.from(`test://bla?storekey=insecure`), kb, sthis);
20
- },
21
- ])("regression of stable cid encoding", (factory) => {
22
- let kycr: CryptoAction;
23
- beforeEach(async () => {
24
- // let url: URI;
25
- // if (runtimeFn().isBrowser) {
26
- // url = URI.from("indexeddb://fp-keybag");
27
- // } else {
28
- // url = URI.merge(`file://./dist/tests/key.bag`, sthis.env.get("FP_KEYBAG_URL"));
29
- // }
30
- kycr = await factory();
31
- });
32
-
33
- it("should encode and decode a stable cid", async () => {
34
- const x1 = await asyncBlockEncode({
35
- value: cborg.encode({ hello: "world" }),
36
- // hashBytes: {
37
- // as: (x: Uint8Array<ArrayBufferLike>): Promise<ByteView<Uint8Array>> => Promise.resolve(x),
38
- // },
39
- hasher: sha256,
40
- codec: kycr.codec(toCryptoRuntime().randomBytes(12)),
41
- });
42
- const x2 = await asyncBlockEncode({
43
- value: cborg.encode({ hello: "world" }),
44
- // hashBytes: {
45
- // as: (x: Uint8Array<ArrayBufferLike>): Promise<ByteView<Uint8Array>> => Promise.resolve(x),
46
- // },
47
- hasher: sha256,
48
- codec: kycr.codec(toCryptoRuntime().randomBytes(12)),
49
- });
50
- expect(x1.cid).toEqual(x2.cid);
51
- });
52
- it("decode stable cid", async () => {
53
- const x1 = await asyncBlockEncode({
54
- value: cborg.encode({ hello: "world" }),
55
- // hashBytes: {
56
- // as: (x: Uint8Array<ArrayBufferLike>): Promise<ByteView<Uint8Array>> => Promise.resolve(x),
57
- // },
58
- hasher: sha256,
59
- codec: kycr.codec(),
60
- });
61
- const x = await asyncBlockDecode<IvKeyIdData, 24, 18>({
62
- bytes: x1.bytes,
63
- // hashBytes: {
64
- // get: (x: IvKeyIdData): Promise<ByteView<Uint8Array>> => Promise.resolve(x.data as ByteView<Uint8Array<ArrayBufferLike>>),
65
- // },
66
- codec: kycr.codec(),
67
- hasher: sha256,
68
- });
69
- expect(x.cid.toString()).toEqual(x1.cid.toString());
70
- expect(cborg.decode(x.value.data)).toEqual({ hello: "world" });
71
- }, 1000000);
72
- });
@@ -1,137 +0,0 @@
1
- import { runtimeFn, URI } from "@adviser/cement";
2
- import { getFileName } from "@fireproof/core-gateways-base";
3
- import { ensureSuperThis, ensureSuperLog, getStore, inplaceFilter } from "@fireproof/core-runtime";
4
- import { UUID } from "uuidv7";
5
- import { describe, beforeAll, it, expect, assert } from "vitest";
6
-
7
- describe("utils", () => {
8
- const sthis = ensureSuperThis();
9
- const logger = ensureSuperLog(sthis, "getfilename");
10
-
11
- beforeAll(async () => {
12
- await sthis.start();
13
- });
14
-
15
- it("sorts search params", () => {
16
- const url = URI.from("http://example.com?z=1&y=2&x=3");
17
- expect(url.toString()).toEqual("http://example.com/?x=3&y=2&z=1");
18
- });
19
-
20
- const storeOpts = [
21
- {
22
- type: "car",
23
- pathPart: "data",
24
- suffix: ".car",
25
- },
26
- {
27
- type: "file",
28
- pathPart: "data",
29
- suffix: "",
30
- },
31
- {
32
- type: "wal",
33
- pathPart: "wal",
34
- suffix: ".json",
35
- },
36
- {
37
- type: "meta",
38
- pathPart: "meta",
39
- suffix: ".json",
40
- },
41
- ];
42
- it("getfilename plain", () => {
43
- for (const store of storeOpts) {
44
- const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version&suffix=${store.suffix}`);
45
- expect(getFileName(url, logger)).toEqual(`${store.pathPart}/key${store.suffix}`);
46
- }
47
- });
48
-
49
- it("getfilename index", () => {
50
- for (const store of storeOpts) {
51
- const url = URI.from(
52
- `file://./x/path?index=idx&store=${store.type}&name=name&key=key&version=version&suffix=${store.suffix}`,
53
- );
54
- expect(getFileName(url, logger)).toEqual(`idx-${store.pathPart}/key${store.suffix}`);
55
- }
56
- });
57
-
58
- it("getstore", () => {
59
- for (const store of storeOpts) {
60
- const url = URI.from(`file://./x/path?store=${store.type}&name=name&key=key&version=version`);
61
- expect(getStore(url, logger, (...toJoin) => toJoin.join("+"))).toEqual({
62
- fromUrl: store.type,
63
- name: store.pathPart,
64
- pathPart: store.pathPart,
65
- });
66
- }
67
- });
68
-
69
- it("getstore idx", () => {
70
- for (const store of storeOpts) {
71
- const url = URI.from(`file://./x/path?index=ix&store=${store.type}&name=name&key=key&version=version`);
72
- expect(getStore(url, logger, (...toJoin) => toJoin.join("+"))).toEqual({
73
- fromUrl: store.type,
74
- pathPart: store.pathPart,
75
- name: `ix+${store.pathPart}`,
76
- });
77
- }
78
- });
79
-
80
- it("order timeorderednextid", () => {
81
- let last = sthis.timeOrderedNextId().str;
82
- for (let i = 0; i < 10; i++) {
83
- const id = sthis.timeOrderedNextId().str;
84
- const x = UUID.parse(id);
85
- expect(x.getVariant()).toBe("VAR_10");
86
- assert(id !== last, "id should be greater than last");
87
- assert(id.slice(0, 13) >= last.slice(0, 13), `id should be greater than last ${id.slice(0, 13)} ${last.slice(0, 13)}`);
88
- last = id;
89
- }
90
- });
91
- it("timeorderednextid is uuidv7", () => {
92
- const id = sthis.timeOrderedNextId(0xcafebabebeef).str;
93
- expect(id.slice(0, 15)).toBe("cafebabe-beef-7");
94
- });
95
-
96
- it("inplaceFilter empty", () => {
97
- const s: string[] = [];
98
- expect(inplaceFilter(s, () => false)).toEqual([]);
99
- expect(inplaceFilter(s, () => true)).toEqual([]);
100
- });
101
-
102
- it("inplaceFilter sized filtered", () => {
103
- const s = new Array(100).fill("a").map((a, i) => `${a}${i.toString()}`);
104
- expect(inplaceFilter(s, () => false)).toEqual([]);
105
- });
106
- it("inplaceFilter sized unfiltered", () => {
107
- const s = new Array(100).fill("a").map((a, i) => `${a}${i.toString()}`);
108
- const ref = [...s];
109
- expect(inplaceFilter(s, () => true)).toEqual(ref);
110
- });
111
-
112
- it("inplaceFilter sized mod 7", () => {
113
- const s = new Array(100).fill("a").map((a, i) => `${a}${i.toString()}`);
114
- const ref = [...s];
115
- for (let i = 99; i >= 0; i--) {
116
- if (!(i % 7)) {
117
- ref.splice(i, 1);
118
- }
119
- }
120
- expect(inplaceFilter(s, (_, j) => !!(j % 7))).toEqual(ref);
121
- expect(s.length).toBe(85);
122
- });
123
- });
124
-
125
- describe("runtime", () => {
126
- it("runtime", () => {
127
- const isDeno = !!(typeof process === "object" && process.versions?.deno);
128
- const isNode = !isDeno && !!(typeof process === "object" && process.versions?.node);
129
- expect(runtimeFn()).toEqual({
130
- isBrowser: !(isNode || isDeno),
131
- isCFWorker: false,
132
- isDeno: isDeno,
133
- isNodeIsh: isNode,
134
- isReactNative: false,
135
- });
136
- });
137
- });