@instantdb/core
Advanced tools
Comparing version 0.7.15 to 0.7.16
@@ -20,3 +20,5 @@ type WhereClause = { | ||
}; | ||
type ResponseObject<K, Schema> = K extends keyof Schema ? InstantObject & Schema[K] : InstantObject; | ||
type ResponseObject<K, Schema> = K extends keyof Schema ? { | ||
id: string; | ||
} & Schema[K] : InstantObject; | ||
type IsEmptyObject<T> = T extends Record<string, never> ? true : false; | ||
@@ -23,0 +25,0 @@ type ResponseOf<Q, Schema> = { |
@@ -23,3 +23,3 @@ // Query | ||
// Basic good inputs succeed | ||
const r1 = dummyQuery({ users: {} }); | ||
const r = dummyQuery({ users: {} }); | ||
// ----------- | ||
@@ -30,17 +30,17 @@ // Basic bad inputs fails | ||
// @ts-expect-error | ||
const r2 = dummyQuery({ users: "" }); | ||
const r3 = dummyQuery({ users: "" }); | ||
// ---------------------- | ||
// Good $ clauses succeed | ||
const r3 = dummyQuery({ users: { $: { where: { foo: 1 } } } }); | ||
const r4 = dummyQuery({ users: { $: { where: { foo: "str" } } } }); | ||
const r5 = dummyQuery({ users: { $: { where: { foo: true } } } }); | ||
const r6 = dummyQuery({ users: { $: { where: { "foo.bar.baz": 1 } } } }); | ||
const r4 = dummyQuery({ users: { $: { where: { foo: 1 } } } }); | ||
const r5 = dummyQuery({ users: { $: { where: { foo: "str" } } } }); | ||
const r6 = dummyQuery({ users: { $: { where: { foo: true } } } }); | ||
const r7 = dummyQuery({ users: { $: { where: { "foo.bar.baz": 1 } } } }); | ||
// ------------------ | ||
// Bad $ clauses fail | ||
// @ts-expect-error | ||
const r7 = dummyQuery({ users: { $: { where: "foo" } } }); | ||
const r8 = dummyQuery({ users: { $: { where: "foo" } } }); | ||
// @ts-expect-error | ||
const r8 = dummyQuery({ users: { $: { where: { foo: {} } } } }); | ||
const r9 = dummyQuery({ users: { $: { where: { foo: {} } } } }); | ||
// @ts-expect-error | ||
const r9 = dummyQuery({ users: { $: { where2: 1 } } }); | ||
const r10 = dummyQuery({ users: { $: { where2: 1 } } }); | ||
// ---------------- | ||
@@ -70,3 +70,3 @@ // Good Nested queries succeed | ||
}; | ||
const sanityCheckResponses = () => { | ||
const sanityCheckSchemalessResponses = () => { | ||
// Simple Response | ||
@@ -86,3 +86,3 @@ const r1 = dummyQuery({ users: {} }); | ||
}; | ||
function sanityCheckSchemaQueries() { | ||
function sanityCheckSchemadResponses() { | ||
// simple response | ||
@@ -94,4 +94,11 @@ const r1 = dummySchemaQuery({ users: {} }); | ||
}); | ||
// id included, but no other keys are allowed | ||
const r3 = dummySchemaQuery({ users: {} }); | ||
const u = r3.users[0]; | ||
const id = u.id; | ||
const name = u.name; | ||
// @ts-expect-error | ||
const title = u.title; | ||
} | ||
export {}; | ||
//# sourceMappingURL=queryTypes.js.map |
@@ -101,6 +101,23 @@ import { produce } from "immer"; | ||
} | ||
// (XXX): Hack to ensure that we set a date that will be bigger than | ||
// anything committed to the server. | ||
// eventually we may need something different, | ||
// if we wanted to 'expose' the createdAt and updatedAt to the client | ||
/** | ||
* (XXX) | ||
* Two hacks here, for generating a `createdAt` | ||
* | ||
* 1. We multiply Date.now() by 10, to make sure that | ||
* `createdAt` is always greater than anything the server | ||
* could return | ||
* | ||
* We do this because right now we know we _only_ insert | ||
* triples as optimistic updates. | ||
* | ||
* 2. We increment by `_seed`, to make sure there are no | ||
* two triples with the same `createdAt`. This is | ||
* done to make tests more predictable. | ||
* | ||
* We may need to rethink this. Because we * 10, we can't | ||
* use this value as an _actual_ `createdAt` timestamp. | ||
* Eventually we may want too though; For example, we could | ||
* use `createdAt` for each triple, to infer a `createdAt` and | ||
* `updatedAt` value for each object. | ||
*/ | ||
return createdAt || Date.now() * 10 + _seed++; | ||
@@ -107,0 +124,0 @@ } |
@@ -20,3 +20,5 @@ type WhereClause = { | ||
}; | ||
type ResponseObject<K, Schema> = K extends keyof Schema ? InstantObject & Schema[K] : InstantObject; | ||
type ResponseObject<K, Schema> = K extends keyof Schema ? { | ||
id: string; | ||
} & Schema[K] : InstantObject; | ||
type IsEmptyObject<T> = T extends Record<string, never> ? true : false; | ||
@@ -23,0 +25,0 @@ type ResponseOf<Q, Schema> = { |
@@ -25,3 +25,3 @@ "use strict"; | ||
// Basic good inputs succeed | ||
const r1 = dummyQuery({ users: {} }); | ||
const r = dummyQuery({ users: {} }); | ||
// ----------- | ||
@@ -32,17 +32,17 @@ // Basic bad inputs fails | ||
// @ts-expect-error | ||
const r2 = dummyQuery({ users: "" }); | ||
const r3 = dummyQuery({ users: "" }); | ||
// ---------------------- | ||
// Good $ clauses succeed | ||
const r3 = dummyQuery({ users: { $: { where: { foo: 1 } } } }); | ||
const r4 = dummyQuery({ users: { $: { where: { foo: "str" } } } }); | ||
const r5 = dummyQuery({ users: { $: { where: { foo: true } } } }); | ||
const r6 = dummyQuery({ users: { $: { where: { "foo.bar.baz": 1 } } } }); | ||
const r4 = dummyQuery({ users: { $: { where: { foo: 1 } } } }); | ||
const r5 = dummyQuery({ users: { $: { where: { foo: "str" } } } }); | ||
const r6 = dummyQuery({ users: { $: { where: { foo: true } } } }); | ||
const r7 = dummyQuery({ users: { $: { where: { "foo.bar.baz": 1 } } } }); | ||
// ------------------ | ||
// Bad $ clauses fail | ||
// @ts-expect-error | ||
const r7 = dummyQuery({ users: { $: { where: "foo" } } }); | ||
const r8 = dummyQuery({ users: { $: { where: "foo" } } }); | ||
// @ts-expect-error | ||
const r8 = dummyQuery({ users: { $: { where: { foo: {} } } } }); | ||
const r9 = dummyQuery({ users: { $: { where: { foo: {} } } } }); | ||
// @ts-expect-error | ||
const r9 = dummyQuery({ users: { $: { where2: 1 } } }); | ||
const r10 = dummyQuery({ users: { $: { where2: 1 } } }); | ||
// ---------------- | ||
@@ -72,3 +72,3 @@ // Good Nested queries succeed | ||
}; | ||
const sanityCheckResponses = () => { | ||
const sanityCheckSchemalessResponses = () => { | ||
// Simple Response | ||
@@ -88,3 +88,3 @@ const r1 = dummyQuery({ users: {} }); | ||
}; | ||
function sanityCheckSchemaQueries() { | ||
function sanityCheckSchemadResponses() { | ||
// simple response | ||
@@ -96,3 +96,10 @@ const r1 = dummySchemaQuery({ users: {} }); | ||
}); | ||
// id included, but no other keys are allowed | ||
const r3 = dummySchemaQuery({ users: {} }); | ||
const u = r3.users[0]; | ||
const id = u.id; | ||
const name = u.name; | ||
// @ts-expect-error | ||
const title = u.title; | ||
} | ||
//# sourceMappingURL=queryTypes.js.map |
@@ -105,6 +105,23 @@ "use strict"; | ||
} | ||
// (XXX): Hack to ensure that we set a date that will be bigger than | ||
// anything committed to the server. | ||
// eventually we may need something different, | ||
// if we wanted to 'expose' the createdAt and updatedAt to the client | ||
/** | ||
* (XXX) | ||
* Two hacks here, for generating a `createdAt` | ||
* | ||
* 1. We multiply Date.now() by 10, to make sure that | ||
* `createdAt` is always greater than anything the server | ||
* could return | ||
* | ||
* We do this because right now we know we _only_ insert | ||
* triples as optimistic updates. | ||
* | ||
* 2. We increment by `_seed`, to make sure there are no | ||
* two triples with the same `createdAt`. This is | ||
* done to make tests more predictable. | ||
* | ||
* We may need to rethink this. Because we * 10, we can't | ||
* use this value as an _actual_ `createdAt` timestamp. | ||
* Eventually we may want too though; For example, we could | ||
* use `createdAt` for each triple, to infer a `createdAt` and | ||
* `updatedAt` value for each object. | ||
*/ | ||
return createdAt || Date.now() * 10 + _seed++; | ||
@@ -111,0 +128,0 @@ } |
{ | ||
"name": "@instantdb/core", | ||
"version": "0.7.15", | ||
"version": "0.7.16", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -24,3 +24,3 @@ // Query | ||
type ResponseObject<K, Schema> = K extends keyof Schema | ||
? InstantObject & Schema[K] | ||
? { id: string } & Schema[K] | ||
: InstantObject; | ||
@@ -88,3 +88,3 @@ | ||
_query: Exactly<Query, Q>, | ||
): ResponseOf<Remove$<Q>, unknown> { | ||
): QueryResponse<Q, unknown> { | ||
return 1 as any; | ||
@@ -108,3 +108,3 @@ } | ||
_query: Exactly<Query, Q>, | ||
): ResponseOf<Remove$<Q>, ExSchema> { | ||
): QueryResponse<Q, ExSchema> { | ||
return 1 as any; | ||
@@ -116,3 +116,3 @@ } | ||
// Basic good inputs succeed | ||
const r1 = dummyQuery({ users: {} }); | ||
const r = dummyQuery({ users: {} }); | ||
@@ -125,3 +125,3 @@ // ----------- | ||
// @ts-expect-error | ||
const r2 = dummyQuery({ users: "" }); | ||
const r3 = dummyQuery({ users: "" }); | ||
@@ -131,6 +131,6 @@ // ---------------------- | ||
const r3 = dummyQuery({ users: { $: { where: { foo: 1 } } } }); | ||
const r4 = dummyQuery({ users: { $: { where: { foo: "str" } } } }); | ||
const r5 = dummyQuery({ users: { $: { where: { foo: true } } } }); | ||
const r6 = dummyQuery({ users: { $: { where: { "foo.bar.baz": 1 } } } }); | ||
const r4 = dummyQuery({ users: { $: { where: { foo: 1 } } } }); | ||
const r5 = dummyQuery({ users: { $: { where: { foo: "str" } } } }); | ||
const r6 = dummyQuery({ users: { $: { where: { foo: true } } } }); | ||
const r7 = dummyQuery({ users: { $: { where: { "foo.bar.baz": 1 } } } }); | ||
@@ -141,7 +141,7 @@ // ------------------ | ||
// @ts-expect-error | ||
const r7 = dummyQuery({ users: { $: { where: "foo" } } }); | ||
const r8 = dummyQuery({ users: { $: { where: "foo" } } }); | ||
// @ts-expect-error | ||
const r8 = dummyQuery({ users: { $: { where: { foo: {} } } } }); | ||
const r9 = dummyQuery({ users: { $: { where: { foo: {} } } } }); | ||
// @ts-expect-error | ||
const r9 = dummyQuery({ users: { $: { where2: 1 } } }); | ||
const r10 = dummyQuery({ users: { $: { where2: 1 } } }); | ||
@@ -177,3 +177,3 @@ // ---------------- | ||
const sanityCheckResponses = () => { | ||
const sanityCheckSchemalessResponses = () => { | ||
// Simple Response | ||
@@ -196,3 +196,3 @@ const r1: { users: InstantObject[] } = dummyQuery({ users: {} }); | ||
function sanityCheckSchemaQueries() { | ||
function sanityCheckSchemadResponses() { | ||
// simple response | ||
@@ -204,2 +204,9 @@ const r1: { users: ExUser[] } = dummySchemaQuery({ users: {} }); | ||
}); | ||
// id included, but no other keys are allowed | ||
const r3 = dummySchemaQuery({ users: {} }); | ||
const u = r3.users[0]; | ||
const id: string = u.id; | ||
const name: string = u.name; | ||
// @ts-expect-error | ||
const title: string = u.title; | ||
} |
@@ -112,6 +112,23 @@ import { produce } from "immer"; | ||
// (XXX): Hack to ensure that we set a date that will be bigger than | ||
// anything committed to the server. | ||
// eventually we may need something different, | ||
// if we wanted to 'expose' the createdAt and updatedAt to the client | ||
/** | ||
* (XXX) | ||
* Two hacks here, for generating a `createdAt` | ||
* | ||
* 1. We multiply Date.now() by 10, to make sure that | ||
* `createdAt` is always greater than anything the server | ||
* could return | ||
* | ||
* We do this because right now we know we _only_ insert | ||
* triples as optimistic updates. | ||
* | ||
* 2. We increment by `_seed`, to make sure there are no | ||
* two triples with the same `createdAt`. This is | ||
* done to make tests more predictable. | ||
* | ||
* We may need to rethink this. Because we * 10, we can't | ||
* use this value as an _actual_ `createdAt` timestamp. | ||
* Eventually we may want too though; For example, we could | ||
* use `createdAt` for each triple, to infer a `createdAt` and | ||
* `updatedAt` value for each object. | ||
*/ | ||
return createdAt || Date.now() * 10 + _seed++; | ||
@@ -118,0 +135,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1433333
32700