Skip to content

Commit 8e1fe92

Browse files
authored
Merge pull request #1338 from cardstack/cs-6897-during-indexing-save-instance-json-source-to-source-column
Include card instance source in index DB
2 parents 7bd25ad + 95c9876 commit 8e1fe92

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

Diff for: packages/runtime-common/indexer.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ interface IndexedModule {
9292
export interface IndexedInstance {
9393
type: 'instance';
9494
instance: CardResource;
95+
source: string;
9596
isolatedHtml: string | null;
9697
searchDoc: Record<string, any> | null;
9798
types: string[] | null;
9899
deps: string[] | null;
99100
realmVersion: number;
100101
realmURL: string;
101102
indexedAt: number | null;
102-
// TODO source (cs-6897)
103103
}
104104
interface IndexedError {
105105
type: 'error';
@@ -238,14 +238,15 @@ export class Indexer {
238238
realm_version: realmVersion,
239239
realm_url: realmURL,
240240
indexed_at: indexedAt,
241+
source,
241242
types,
242243
deps,
243244
} = maybeResult;
244-
if (!instance) {
245+
if (!instance || !source) {
245246
throw new Error(
246247
`bug: index entry for ${href} with opts: ${JSON.stringify(
247248
opts,
248-
)} has neither an error_doc nor a pristine_doc`,
249+
)} has neither an error_doc nor a pristine_doc/source`,
249250
);
250251
}
251252
return {
@@ -256,6 +257,7 @@ export class Indexer {
256257
searchDoc,
257258
types,
258259
indexedAt,
260+
source,
259261
deps,
260262
realmVersion,
261263
};

Diff for: packages/runtime-common/tests/indexer-test.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,20 @@ const tests = Object.freeze({
786786
},
787787

788788
'can get "production" index entry': async (assert, { indexer }) => {
789+
let originalResource: LooseCardResource = {
790+
id: `${testRealmURL}1`,
791+
type: 'card',
792+
attributes: {
793+
name: 'Mango',
794+
},
795+
meta: {
796+
adoptsFrom: {
797+
module: `./person`,
798+
name: 'Person',
799+
},
800+
},
801+
};
802+
let originalSource = JSON.stringify(originalResource);
789803
await setupIndex(
790804
indexer,
791805
[{ realm_url: testRealmURL, current_version: 1 }],
@@ -794,19 +808,8 @@ const tests = Object.freeze({
794808
url: `${testRealmURL}1.json`,
795809
realm_version: 1,
796810
realm_url: testRealmURL,
797-
pristine_doc: {
798-
id: `${testRealmURL}1`,
799-
type: 'card',
800-
attributes: {
801-
name: 'Mango',
802-
},
803-
meta: {
804-
adoptsFrom: {
805-
module: `./person`,
806-
name: 'Person',
807-
},
808-
},
809-
} as LooseCardResource,
811+
pristine_doc: originalResource,
812+
source: originalSource,
810813
},
811814
],
812815
);
@@ -854,6 +857,7 @@ const tests = Object.freeze({
854857
},
855858
},
856859
},
860+
source: originalSource,
857861
searchDoc: null,
858862
deps: null,
859863
types: null,
@@ -902,12 +906,13 @@ const tests = Object.freeze({
902906
},
903907
},
904908
};
909+
let source = JSON.stringify(resource);
905910
let batch = await indexer.createBatch(new URL(testRealmURL));
906911
await batch.invalidate(new URL(`${testRealmURL}1.json`));
907912
await batch.updateEntry(new URL(`${testRealmURL}1.json`), {
908913
type: 'instance',
909914
resource,
910-
source: JSON.stringify(resource),
915+
source,
911916
searchData: { name: 'Van Gogh' },
912917
deps: new Set(),
913918
types: [],
@@ -936,6 +941,7 @@ const tests = Object.freeze({
936941
},
937942
},
938943
},
944+
source,
939945
searchDoc: { name: 'Van Gogh' },
940946
deps: [],
941947
types: [],

0 commit comments

Comments
 (0)