@concordance-wiki/typing 0.1.0
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.
- package/LICENSE +674 -0
- package/README.md +7 -0
- package/dist/application.d.ts +19 -0
- package/dist/application.d.ts.map +1 -0
- package/dist/application.js +18 -0
- package/dist/application.js.map +1 -0
- package/dist/cascade.d.ts +26 -0
- package/dist/cascade.d.ts.map +1 -0
- package/dist/cascade.js +78 -0
- package/dist/cascade.js.map +1 -0
- package/dist/domains.d.ts +33 -0
- package/dist/domains.d.ts.map +1 -0
- package/dist/domains.js +96 -0
- package/dist/domains.js.map +1 -0
- package/dist/entity.d.ts +20 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +149 -0
- package/dist/entity.js.map +1 -0
- package/dist/filing.d.ts +17 -0
- package/dist/filing.d.ts.map +1 -0
- package/dist/filing.js +48 -0
- package/dist/filing.js.map +1 -0
- package/dist/frontmatter.d.ts +3 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +7 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/resource.d.ts +38 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +110 -0
- package/dist/resource.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Config, type Entity, type Finding } from "@concordance-wiki/core";
|
|
2
|
+
import type { IngestedSource, ParsedMarkdown } from "@concordance-wiki/ingest";
|
|
3
|
+
import type { Profile } from "@concordance-wiki/profile";
|
|
4
|
+
import { type Resource } from "./resource.js";
|
|
5
|
+
export { resolveApplication, type ApplicationOrigin, type ResolveApplicationInput, type ResolvedApplication, } from "./application.js";
|
|
6
|
+
export { FALLBACK_TYPE, resolveType, ruleMatches, type ResolvedType, type ResolveTypeInput, } from "./cascade.js";
|
|
7
|
+
export { compileDomains, resolveDomain, UNCLASSIFIED_DOMAIN, type CompiledDomain, type DomainMatcher, type DomainOrigin, type ResolvedDomain, } from "./domains.js";
|
|
8
|
+
export { buildEntity, typeSuffixesOf, type BuildEntityInput, type BuiltEntity } from "./entity.js";
|
|
9
|
+
export { filingFindings, type FilingInput } from "./filing.js";
|
|
10
|
+
export { buildResourceEntity, resourceAttributes, type BuildResourceEntityInput, type BuiltResourceEntity, type Resource, } from "./resource.js";
|
|
11
|
+
export interface TypeSourcesInput {
|
|
12
|
+
sources: IngestedSource[];
|
|
13
|
+
/** Parsed markdown files keyed by `<source name>/<path>`; a file without a document is skipped. */
|
|
14
|
+
documents: ReadonlyMap<string, ParsedMarkdown>;
|
|
15
|
+
/** The other files a reader or a converter knows, keyed the same way; a file listed nowhere is not an entity. */
|
|
16
|
+
resources?: ReadonlyMap<string, Resource>;
|
|
17
|
+
config: Config;
|
|
18
|
+
profile: Profile;
|
|
19
|
+
}
|
|
20
|
+
export interface TypedSources {
|
|
21
|
+
entities: Entity[];
|
|
22
|
+
findings: Finding[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds one entity per parsed markdown file and per known resource, files it under its
|
|
26
|
+
* application and domain, resolves duplicate identifiers and sorts everything canonically.
|
|
27
|
+
*/
|
|
28
|
+
export declare function typeSources(input: TypeSourcesInput): TypedSources;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,OAAO,EAEb,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAgB,cAAc,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAIzD,OAAO,EA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import { compareEntities, compareFindings, resolveDuplicates, } from "@concordance-wiki/core";
|
|
2
|
+
import { compileDomains } from "./domains.js";
|
|
3
|
+
import { buildEntity } from "./entity.js";
|
|
4
|
+
import { buildResourceEntity } from "./resource.js";
|
|
5
|
+
export { resolveApplication, } from "./application.js";
|
|
6
|
+
export { FALLBACK_TYPE, resolveType, ruleMatches, } from "./cascade.js";
|
|
7
|
+
export { compileDomains, resolveDomain, UNCLASSIFIED_DOMAIN, } from "./domains.js";
|
|
8
|
+
export { buildEntity, typeSuffixesOf } from "./entity.js";
|
|
9
|
+
export { filingFindings } from "./filing.js";
|
|
10
|
+
export { buildResourceEntity, resourceAttributes, } from "./resource.js";
|
|
11
|
+
function configOf(config, name) {
|
|
12
|
+
const found = config.sources.find((source) => source.name === name);
|
|
13
|
+
if (found === undefined) {
|
|
14
|
+
throw new Error(`ingested source "${name}" is not declared in the configuration`);
|
|
15
|
+
}
|
|
16
|
+
return found;
|
|
17
|
+
}
|
|
18
|
+
/** The entity of a file: from its parsed note, or from its resource; nothing when the file has neither. */
|
|
19
|
+
function buildOne(input, filing, file) {
|
|
20
|
+
const key = `${filing.source.name}/${file.path}`;
|
|
21
|
+
if (file.path.endsWith(".md")) {
|
|
22
|
+
const document = input.documents.get(key);
|
|
23
|
+
return document === undefined ? undefined : buildEntity({ ...filing, file, document });
|
|
24
|
+
}
|
|
25
|
+
const resource = input.resources?.get(key);
|
|
26
|
+
return resource === undefined ? undefined : buildResourceEntity({ ...filing, file, resource });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Builds one entity per parsed markdown file and per known resource, files it under its
|
|
30
|
+
* application and domain, resolves duplicate identifiers and sorts everything canonically.
|
|
31
|
+
*/
|
|
32
|
+
export function typeSources(input) {
|
|
33
|
+
const { sources, config, profile } = input;
|
|
34
|
+
const applications = config.applications ?? [];
|
|
35
|
+
const domains = compileDomains(config.domains ?? []);
|
|
36
|
+
const candidates = [];
|
|
37
|
+
const findings = [];
|
|
38
|
+
for (const source of sources) {
|
|
39
|
+
const filing = {
|
|
40
|
+
source,
|
|
41
|
+
sourceConfig: configOf(config, source.name),
|
|
42
|
+
profile,
|
|
43
|
+
applications,
|
|
44
|
+
domains,
|
|
45
|
+
};
|
|
46
|
+
for (const file of source.files) {
|
|
47
|
+
const built = buildOne(input, filing, file);
|
|
48
|
+
if (built === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
candidates.push({
|
|
51
|
+
id: built.entity.id,
|
|
52
|
+
source: source.name,
|
|
53
|
+
path: file.path,
|
|
54
|
+
entity: built.entity,
|
|
55
|
+
});
|
|
56
|
+
findings.push(...built.findings);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const duplicates = resolveDuplicates(candidates);
|
|
60
|
+
return {
|
|
61
|
+
entities: duplicates.kept.map((candidate) => candidate.entity).sort(compareEntities),
|
|
62
|
+
findings: [...findings, ...duplicates.findings].sort(compareFindings),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,iBAAiB,GAMlB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAAE,cAAc,EAAsB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAoB,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAiB,MAAM,eAAe,CAAC;AAEnE,OAAO,EACL,kBAAkB,GAInB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,GAGZ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,aAAa,EACb,mBAAmB,GAKpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,cAAc,EAA2C,MAAM,aAAa,CAAC;AACnG,OAAO,EAAE,c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eAAe,CAAC;KACtE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ApplicationConfig, type Entity, type Finding, type SourceConfig } from "@concordance-wiki/core";
|
|
2
|
+
import type { IngestedFile, IngestedSource } from "@concordance-wiki/ingest";
|
|
3
|
+
import type { Profile } from "@concordance-wiki/profile";
|
|
4
|
+
import { type DomainMatcher } from "./domains.js";
|
|
5
|
+
/** A file of a source that is not a note: what its reader knows about it, before it becomes an entity. */
|
|
6
|
+
export interface Resource {
|
|
7
|
+
/** Lowercase extension without its dot: `pptx`, `pdf`, `vtt`. */
|
|
8
|
+
format: string;
|
|
9
|
+
/** The native properties its reader reports (title, author, dates, counts); empty without a reader. */
|
|
10
|
+
metadata: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface BuildResourceEntityInput {
|
|
13
|
+
file: IngestedFile;
|
|
14
|
+
source: IngestedSource;
|
|
15
|
+
sourceConfig: SourceConfig;
|
|
16
|
+
resource: Resource;
|
|
17
|
+
profile: Profile;
|
|
18
|
+
applications: readonly ApplicationConfig[];
|
|
19
|
+
domains: DomainMatcher;
|
|
20
|
+
}
|
|
21
|
+
export interface BuiltResourceEntity {
|
|
22
|
+
entity: Entity;
|
|
23
|
+
findings: Finding[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The attributes of a resource: the defaults of the matching rules, the metadata of the reader
|
|
27
|
+
* under their own keys, the format, and `date` set from the document's own dates so that the
|
|
28
|
+
* highlight of the `document` type has something to show; keys sorted.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resourceAttributes(resource: Resource, defaults: Record<string, unknown>): Record<string, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* One entity per resource, typed by the same cascade as a note without a frontmatter (the
|
|
33
|
+
* source's types, then its rules, `ext` matches included), filed under the source's application
|
|
34
|
+
* and the domain of its path. Its identifier keeps the extension, so that a deck and the note
|
|
35
|
+
* that shares its base name stay two entities until the twin reconciliation joins them.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildResourceEntity(input: BuildResourceEntityInput): BuiltResourceEntity;
|
|
38
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,MAAM,EAEX,KAAK,OAAO,EACZ,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAIzD,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAGjE,0GAA0G;AAC1G,MAAM,WAAW,QAAQ;IACvB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,uGAAuG;IACvG,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,cAAc,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC3C,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AA8BD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgBzB;AAYD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,mBAAmB,CAyCxF"}
|
package/dist/resource.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { identifierFor, } from "@concordance-wiki/core";
|
|
2
|
+
import { resolveApplication } from "./application.js";
|
|
3
|
+
import { resolveType } from "./cascade.js";
|
|
4
|
+
import { resolveDomain } from "./domains.js";
|
|
5
|
+
import { filingFindings } from "./filing.js";
|
|
6
|
+
/** Metadata keys that do not become attributes: the title names the entity, the producing application is renamed. */
|
|
7
|
+
const RENAMED = {
|
|
8
|
+
title: undefined,
|
|
9
|
+
application: "producer",
|
|
10
|
+
};
|
|
11
|
+
const DEFAULT_STATUS = "valid";
|
|
12
|
+
// Code-unit order, not locale order: the output must not depend on the collation data of the runtime.
|
|
13
|
+
function byCodeUnit(a, b) {
|
|
14
|
+
return Number(a > b) - Number(a < b);
|
|
15
|
+
}
|
|
16
|
+
function fileTitle(path) {
|
|
17
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
18
|
+
return name.replace(/\.[^.]+$/, "");
|
|
19
|
+
}
|
|
20
|
+
function titleOf(metadata, path) {
|
|
21
|
+
const title = metadata["title"];
|
|
22
|
+
return typeof title === "string" && title.trim() !== "" ? title.trim() : fileTitle(path);
|
|
23
|
+
}
|
|
24
|
+
function statusOf(profile) {
|
|
25
|
+
const fallback = profile.common_attributes?.["status"]?.default;
|
|
26
|
+
return typeof fallback === "string" ? fallback : DEFAULT_STATUS;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The attributes of a resource: the defaults of the matching rules, the metadata of the reader
|
|
30
|
+
* under their own keys, the format, and `date` set from the document's own dates so that the
|
|
31
|
+
* highlight of the `document` type has something to show; keys sorted.
|
|
32
|
+
*/
|
|
33
|
+
export function resourceAttributes(resource, defaults) {
|
|
34
|
+
const merged = { format: resource.format };
|
|
35
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
36
|
+
if (key !== "application")
|
|
37
|
+
merged[key] = value;
|
|
38
|
+
}
|
|
39
|
+
for (const [key, value] of Object.entries(resource.metadata)) {
|
|
40
|
+
const name = key in RENAMED ? RENAMED[key] : key;
|
|
41
|
+
if (name !== undefined)
|
|
42
|
+
merged[name] = value;
|
|
43
|
+
}
|
|
44
|
+
const date = resource.metadata["modified"] ?? resource.metadata["created"];
|
|
45
|
+
if (merged["date"] === undefined && typeof date === "string")
|
|
46
|
+
merged["date"] = date;
|
|
47
|
+
const attributes = {};
|
|
48
|
+
for (const key of Object.keys(merged).sort(byCodeUnit)) {
|
|
49
|
+
attributes[key] = merged[key];
|
|
50
|
+
}
|
|
51
|
+
return attributes;
|
|
52
|
+
}
|
|
53
|
+
function sourceOf(file, source) {
|
|
54
|
+
const location = {
|
|
55
|
+
name: source.name,
|
|
56
|
+
path: file.path,
|
|
57
|
+
line: 1,
|
|
58
|
+
last_modified: file.modifiedAt,
|
|
59
|
+
};
|
|
60
|
+
return file.commit === undefined ? location : { ...location, commit: file.commit };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* One entity per resource, typed by the same cascade as a note without a frontmatter (the
|
|
64
|
+
* source's types, then its rules, `ext` matches included), filed under the source's application
|
|
65
|
+
* and the domain of its path. Its identifier keeps the extension, so that a deck and the note
|
|
66
|
+
* that shares its base name stay two entities until the twin reconciliation joins them.
|
|
67
|
+
*/
|
|
68
|
+
export function buildResourceEntity(input) {
|
|
69
|
+
const { file, source, sourceConfig, resource, profile, applications, domains } = input;
|
|
70
|
+
const identifier = identifierFor({ source: source.name, path: file.path, typeSuffixes: [] });
|
|
71
|
+
const id = `${identifier.id}.${resource.format}`;
|
|
72
|
+
const resolved = resolveType({ source: sourceConfig, path: file.path, frontmatter: {}, profile });
|
|
73
|
+
const application = resolveApplication({
|
|
74
|
+
source: sourceConfig,
|
|
75
|
+
ruleDefaults: resolved.defaults,
|
|
76
|
+
frontmatterApplication: undefined,
|
|
77
|
+
applications,
|
|
78
|
+
});
|
|
79
|
+
const domain = resolveDomain(file.path, undefined, domains);
|
|
80
|
+
const entity = {
|
|
81
|
+
id,
|
|
82
|
+
type: resolved.type,
|
|
83
|
+
title: titleOf(resource.metadata, file.path),
|
|
84
|
+
aliases: [],
|
|
85
|
+
locale: source.locale,
|
|
86
|
+
...(application.application === undefined ? {} : { application: application.application }),
|
|
87
|
+
domain: domain.domain,
|
|
88
|
+
status: statusOf(profile),
|
|
89
|
+
type_origin: resolved.origin,
|
|
90
|
+
graph: profile.types[resolved.type]?.graph ?? "full",
|
|
91
|
+
attributes: resourceAttributes(resource, resolved.defaults),
|
|
92
|
+
source: sourceOf(file, source),
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
entity,
|
|
96
|
+
findings: [
|
|
97
|
+
...resolved.findings,
|
|
98
|
+
...filingFindings({
|
|
99
|
+
id,
|
|
100
|
+
type: resolved.type,
|
|
101
|
+
source: source.name,
|
|
102
|
+
path: file.path,
|
|
103
|
+
profile,
|
|
104
|
+
application,
|
|
105
|
+
domain,
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAMd,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAyB7C,qHAAqH;AACrH,MAAM,OAAO,GAAiD;IAC5D,KAAK,EAAE,SAAS;IAChB,WAAW,EAAE,UAAU;CACxB,CAAC;AAEF,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B,sGAAsG;AACtG,SAAS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,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,MAAM;QACpD,UAAU,EAAE,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC;QAC3D,MAAM,EAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;KAC/B,CAAC;IACF,OAAO;QACL,MAAM;QACN,QAAQ,EAAE;YACR,GAAG,QAAQ,CAAC,QAAQ;YACpB,GAAG,cAAc,CAAC;gBAChB,EAAE;gBACF,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO;gBACP,WAAW;gBACX,MAAM;aACP,CAAC;SACH;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@concordance-wiki/typing",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Type cascade, identifiers, application and domain resolution.",
|
|
5
|
+
"license": "GPL-3.0-or-later",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/concordance-wiki/concordance.git",
|
|
9
|
+
"directory": "packages/typing"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/concordance-wiki/concordance/tree/main/packages/typing#readme",
|
|
12
|
+
"bugs": "https://github.com/concordance-wiki/concordance/issues",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"typecheck": "tsc -b tsconfig.json"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@concordance-wiki/core": "workspace:*",
|
|
37
|
+
"@concordance-wiki/ingest": "workspace:*",
|
|
38
|
+
"@concordance-wiki/profile": "workspace:*"
|
|
39
|
+
}
|
|
40
|
+
}
|