@looply/core 0.2.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -75,4 +75,5 @@ export * from './project-origin';
75
75
  export * from './project-graph';
76
76
  export * from './graph-queries';
77
77
  export * from './graph-context';
78
+ export * from './repo-url';
78
79
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAA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U,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -91,4 +91,5 @@ __exportStar(require("./project-origin"), exports);
91
91
  __exportStar(require("./project-graph"), exports);
92
92
  __exportStar(require("./graph-queries"), exports);
93
93
  __exportStar(require("./graph-context"), exports);
94
+ __exportStar(require("./repo-url"), exports);
94
95
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,oDAAkC;AAClC,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,yCAAuB;AACvB,+CAA6B;AAC7B,kDAAgC;AAChC,uDAAqC;AACrC,wDAAsC;AACtC,2DAAyC;AACzC,uDAAqC;AACrC,+CAA6B;AAC7B,uDAAqC;AACrC,uDAAqC;AACrC,qDAAmC;AACnC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,uDAAqC;AACrC,oDAAkC;AAClC,sDAAoC;AACpC,oDAAkC;AAClC,kDAAgC;AAChC,gDAA8B;AAC9B,uDAAqC;AACrC,8CAA4B;AAC5B,gDAA8B;AAC9B,gDAA8B;AAC9B,iDAA+B;AAC/B,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,oDAAkC;AAClC,kDAAgC;AAChC,qDAAmC;AACnC,gDAA8B;AAC9B,oDAAkC;AAClC,iDAA+B;AAC/B,oDAAkC;AAClC,8CAA4B;AAC5B,oDAAkC;AAClC,0DAAwC;AACxC,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,wDAAsC;AACtC,2CAAyB;AACzB,2CAAyB;AACzB,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAC3B,qDAAmC;AACnC,2CAAyB;AACzB,6CAA2B;AAC3B,kDAAgC;AAChC,uDAAqC;AACrC,sDAAoC;AACpC,wDAAsC;AACtC,6CAA2B;AAC3B,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,mDAAiC;AACjC,oDAAkC;AAClC,+CAA6B;AAC7B,6CAA2B;AAC3B,gDAA8B;AAC9B,mDAAiC;AACjC,kDAAgC;AAChC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC;AAChC,kDAAgC;AAChC,kDAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,oDAAkC;AAClC,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,yCAAuB;AACvB,+CAA6B;AAC7B,kDAAgC;AAChC,uDAAqC;AACrC,wDAAsC;AACtC,2DAAyC;AACzC,uDAAqC;AACrC,+CAA6B;AAC7B,uDAAqC;AACrC,uDAAqC;AACrC,qDAAmC;AACnC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,uDAAqC;AACrC,oDAAkC;AAClC,sDAAoC;AACpC,oDAAkC;AAClC,kDAAgC;AAChC,gDAA8B;AAC9B,uDAAqC;AACrC,8CAA4B;AAC5B,gDAA8B;AAC9B,gDAA8B;AAC9B,iDAA+B;AAC/B,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,oDAAkC;AAClC,kDAAgC;AAChC,qDAAmC;AACnC,gDAA8B;AAC9B,oDAAkC;AAClC,iDAA+B;AAC/B,oDAAkC;AAClC,8CAA4B;AAC5B,oDAAkC;AAClC,0DAAwC;AACxC,qDAAmC;AACnC,mDAAiC;AACjC,kDAAgC;AAChC,wDAAsC;AACtC,2CAAyB;AACzB,2CAAyB;AACzB,gDAA8B;AAC9B,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAC3B,qDAAmC;AACnC,2CAAyB;AACzB,6CAA2B;AAC3B,kDAAgC;AAChC,uDAAqC;AACrC,sDAAoC;AACpC,wDAAsC;AACtC,6CAA2B;AAC3B,gDAA8B;AAC9B,4CAA0B;AAC1B,6CAA2B;AAC3B,mDAAiC;AACjC,oDAAkC;AAClC,+CAA6B;AAC7B,6CAA2B;AAC3B,gDAA8B;AAC9B,mDAAiC;AACjC,kDAAgC;AAChC,mDAAiC;AACjC,mDAAiC;AACjC,kDAAgC;AAChC,kDAAgC;AAChC,kDAAgC;AAChC,6CAA2B"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * WHICH REPOSITORY A PROJECT IS, AS A URL ANYBODY CAN COMPARE.
3
+ *
4
+ * ─────────────────────────────────────────────────────────────────────────────
5
+ * 🔴 ONE FUNCTION, BECAUSE THREE PROGRAMS HAVE TO AGREE ON THE ANSWER.
6
+ *
7
+ * The CLI reads `remote.origin.url` off a checkout and sends it at
8
+ * registration; the server stores it on the project and keys clone requests on
9
+ * it; AutoRyn matches its own workspaces against it. The same repository is
10
+ * written `git@github.com:Acme/api.git` on one laptop, `https://github.com/Acme/api`
11
+ * on another and `ssh://git@github.com/Acme/api/` on a third. If each program
12
+ * normalised in its own words, "is this the same repository?" would have three
13
+ * answers and the unique key on a clone request would let the same repository
14
+ * be cloned twice under two spellings. So the rule lives here, once, and every
15
+ * caller repeats this function rather than a copy of it.
16
+ *
17
+ * ─────────────────────────────────────────────────────────────────────────────
18
+ * 🔴 CREDENTIALS NEVER SURVIVE IT.
19
+ *
20
+ * A remote URL is where people paste tokens: `https://x-access-token:ghp_…@github.com/…`
21
+ * is a working remote, and `git remote -v` prints it. The server's schema
22
+ * promises it stores no credentials (DESIGN §6), so userinfo is dropped before
23
+ * anything else looks at the URL, and there is no flag to keep it.
24
+ *
25
+ * ⚠️ ONLY AN http(s) ANSWER IS AN ANSWER. scp-style (`git@host:owner/name`) and
26
+ * `ssh://` remotes are rewritten to the https URL of the same repository on the
27
+ * same host, because that is the spelling every forge serves and the one a
28
+ * machine without the original's SSH key can still try. Everything else —
29
+ * `file://`, `git://`, a bare local path, a Windows drive path — is `null`. A
30
+ * local path in particular is where the code sits on somebody's disk, which is
31
+ * exactly what `Project.repoPathHash` exists to keep off the server; refusing it
32
+ * here is what keeps a careless remote from leaking one.
33
+ *
34
+ * ⚠️ CASE IS FOLDED ONLY WHERE IT IS MEANINGLESS. Scheme and host are
35
+ * case-insensitive by definition; the path is not (GitHub happens to ignore
36
+ * it, a self-hosted server need not), so `Acme/API` stays `Acme/API`.
37
+ */
38
+ /** The longest normalised URL this accepts. Longer is not a repository a person typed. */
39
+ export declare const REPO_URL_MAX = 500;
40
+ /** The longest repository name a clone request may carry. */
41
+ export declare const REPO_NAME_MAX = 100;
42
+ /**
43
+ * The canonical https URL of a repository, or `null` when the input does not
44
+ * name one this function can vouch for.
45
+ *
46
+ * `null` rather than a throw, so a caller registering a project with an odd
47
+ * remote can simply not record one: an unusual origin is not a reason to fail
48
+ * registration.
49
+ */
50
+ export declare function normaliseRepoUrl(raw: unknown): string | null;
51
+ /**
52
+ * A repository name fit to be a directory: `[A-Za-z0-9._-]` only, at most
53
+ * {@link REPO_NAME_MAX} characters, never `.`/`..`, never starting with `-`
54
+ * (which `git clone` would read as an option) or `.` (a hidden directory
55
+ * nobody asked for). `null` when nothing usable is left.
56
+ *
57
+ * Every run of other characters becomes one `-`, so `my repo (v2)` is
58
+ * `my-repo-v2` rather than a name a shell has to quote.
59
+ */
60
+ export declare function sanitiseRepoName(raw: unknown): string | null;
61
+ /**
62
+ * The default name for a repository: the last path segment of its normalised
63
+ * URL, sanitised. `https://github.com/acme/api` is `api`.
64
+ */
65
+ export declare function repoNameFromUrl(url: string): string | null;
66
+ //# sourceMappingURL=repo-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-url.d.ts","sourceRoot":"","sources":["../src/repo-url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,0FAA0F;AAC1F,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,6DAA6D;AAC7D,eAAO,MAAM,aAAa,MAAM,CAAC;AA0BjC;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAsD5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAS5D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAY1D"}
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ /**
3
+ * WHICH REPOSITORY A PROJECT IS, AS A URL ANYBODY CAN COMPARE.
4
+ *
5
+ * ─────────────────────────────────────────────────────────────────────────────
6
+ * 🔴 ONE FUNCTION, BECAUSE THREE PROGRAMS HAVE TO AGREE ON THE ANSWER.
7
+ *
8
+ * The CLI reads `remote.origin.url` off a checkout and sends it at
9
+ * registration; the server stores it on the project and keys clone requests on
10
+ * it; AutoRyn matches its own workspaces against it. The same repository is
11
+ * written `git@github.com:Acme/api.git` on one laptop, `https://github.com/Acme/api`
12
+ * on another and `ssh://git@github.com/Acme/api/` on a third. If each program
13
+ * normalised in its own words, "is this the same repository?" would have three
14
+ * answers and the unique key on a clone request would let the same repository
15
+ * be cloned twice under two spellings. So the rule lives here, once, and every
16
+ * caller repeats this function rather than a copy of it.
17
+ *
18
+ * ─────────────────────────────────────────────────────────────────────────────
19
+ * 🔴 CREDENTIALS NEVER SURVIVE IT.
20
+ *
21
+ * A remote URL is where people paste tokens: `https://x-access-token:ghp_…@github.com/…`
22
+ * is a working remote, and `git remote -v` prints it. The server's schema
23
+ * promises it stores no credentials (DESIGN §6), so userinfo is dropped before
24
+ * anything else looks at the URL, and there is no flag to keep it.
25
+ *
26
+ * ⚠️ ONLY AN http(s) ANSWER IS AN ANSWER. scp-style (`git@host:owner/name`) and
27
+ * `ssh://` remotes are rewritten to the https URL of the same repository on the
28
+ * same host, because that is the spelling every forge serves and the one a
29
+ * machine without the original's SSH key can still try. Everything else —
30
+ * `file://`, `git://`, a bare local path, a Windows drive path — is `null`. A
31
+ * local path in particular is where the code sits on somebody's disk, which is
32
+ * exactly what `Project.repoPathHash` exists to keep off the server; refusing it
33
+ * here is what keeps a careless remote from leaking one.
34
+ *
35
+ * ⚠️ CASE IS FOLDED ONLY WHERE IT IS MEANINGLESS. Scheme and host are
36
+ * case-insensitive by definition; the path is not (GitHub happens to ignore
37
+ * it, a self-hosted server need not), so `Acme/API` stays `Acme/API`.
38
+ */
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.REPO_NAME_MAX = exports.REPO_URL_MAX = void 0;
41
+ exports.normaliseRepoUrl = normaliseRepoUrl;
42
+ exports.sanitiseRepoName = sanitiseRepoName;
43
+ exports.repoNameFromUrl = repoNameFromUrl;
44
+ /** The longest normalised URL this accepts. Longer is not a repository a person typed. */
45
+ exports.REPO_URL_MAX = 500;
46
+ /** The longest repository name a clone request may carry. */
47
+ exports.REPO_NAME_MAX = 100;
48
+ /**
49
+ * `git@host:owner/name(.git)` — scp-like syntax as git itself parses it: no
50
+ * scheme, a host, a colon, then a path that does not start with `//`.
51
+ *
52
+ * ⚠️ THE HOST MUST BE LONGER THAN ONE CHARACTER. `C:repos/x` is a Windows drive
53
+ * path that git also reads as a local path, and treating `C` as a host would
54
+ * invent `https://c/repos/x` — a URL for a server that does not exist, built
55
+ * from a path that should never have reached the server at all.
56
+ */
57
+ const SCP_LIKE = /^(?:[^@/\s:]+@)?([^@/\s:]{2,}):(?!\/\/)(.+)$/;
58
+ /**
59
+ * Whether an SSH host can be carried over to https as it is.
60
+ *
61
+ * ⚠️ AN SSH HOST CAN BE AN ALIAS. `git@github-work:acme/api` names a `Host`
62
+ * block in somebody's `~/.ssh/config`, not a server, and `https://github-work/…`
63
+ * would be a URL for nothing. A dotted name, `localhost` or an IP literal is a
64
+ * real host; anything else is refused rather than guessed at. It also keeps
65
+ * `javascript:alert(1)` — scp-shaped, to a regex — from becoming a "repository".
66
+ */
67
+ function isRealHost(host) {
68
+ return host.includes('.') || host.toLowerCase() === 'localhost' || host.startsWith('[');
69
+ }
70
+ /**
71
+ * The canonical https URL of a repository, or `null` when the input does not
72
+ * name one this function can vouch for.
73
+ *
74
+ * `null` rather than a throw, so a caller registering a project with an odd
75
+ * remote can simply not record one: an unusual origin is not a reason to fail
76
+ * registration.
77
+ */
78
+ function normaliseRepoUrl(raw) {
79
+ if (typeof raw !== 'string')
80
+ return null;
81
+ const input = raw.trim();
82
+ if (input.length === 0)
83
+ return null;
84
+ // Whitespace inside or a backslash anywhere: not a URL, and a backslash is
85
+ // the signature of a Windows path that would otherwise half-parse.
86
+ if (/\s/.test(input) || input.includes('\\'))
87
+ return null;
88
+ let candidate;
89
+ const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):\/\//.exec(input)?.[1]?.toLowerCase();
90
+ if (scheme === undefined) {
91
+ const scp = SCP_LIKE.exec(input);
92
+ if (!scp || !isRealHost(scp[1]))
93
+ return null;
94
+ candidate = `https://${scp[1]}/${scp[2].replace(/^\/+/, '')}`;
95
+ }
96
+ else if (scheme === 'http' || scheme === 'https') {
97
+ candidate = input;
98
+ }
99
+ else if (scheme === 'ssh' || scheme === 'git+ssh' || scheme === 'ssh+git') {
100
+ // Same host, same path, over https. The SSH port (often 22, sometimes a
101
+ // forge's own) means nothing to the https side, so it is dropped rather
102
+ // than carried onto a URL where it would point at the wrong service.
103
+ let ssh;
104
+ try {
105
+ ssh = new URL(input);
106
+ }
107
+ catch {
108
+ return null;
109
+ }
110
+ if (!isRealHost(ssh.hostname))
111
+ return null;
112
+ candidate = `https://${ssh.hostname}${ssh.pathname}`;
113
+ }
114
+ else {
115
+ return null;
116
+ }
117
+ let url;
118
+ try {
119
+ url = new URL(candidate);
120
+ }
121
+ catch {
122
+ return null;
123
+ }
124
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
125
+ return null;
126
+ if (url.hostname.length === 0)
127
+ return null;
128
+ // Doubled slashes collapsed, then trailing slashes, `.git`, and trailing
129
+ // slashes again — `owner/name.git/` and `owner/name/` are the same repository.
130
+ let path = url.pathname.replace(/\/{2,}/g, '/');
131
+ path = path.replace(/\/+$/, '').replace(/\.git$/i, '').replace(/\/+$/, '');
132
+ // A host alone is a forge, not a repository.
133
+ if (path.length === 0 || path === '/')
134
+ return null;
135
+ // `URL` has already lower-cased the scheme and host. Userinfo, query and
136
+ // fragment are not part of which repository this is; the userinfo is the
137
+ // credential this function exists to drop.
138
+ const port = url.port === '' ? '' : `:${url.port}`;
139
+ const out = `${url.protocol}//${url.hostname}${port}${path}`;
140
+ return out.length > exports.REPO_URL_MAX ? null : out;
141
+ }
142
+ /**
143
+ * A repository name fit to be a directory: `[A-Za-z0-9._-]` only, at most
144
+ * {@link REPO_NAME_MAX} characters, never `.`/`..`, never starting with `-`
145
+ * (which `git clone` would read as an option) or `.` (a hidden directory
146
+ * nobody asked for). `null` when nothing usable is left.
147
+ *
148
+ * Every run of other characters becomes one `-`, so `my repo (v2)` is
149
+ * `my-repo-v2` rather than a name a shell has to quote.
150
+ */
151
+ function sanitiseRepoName(raw) {
152
+ if (typeof raw !== 'string')
153
+ return null;
154
+ const cleaned = raw
155
+ .trim()
156
+ .replace(/[^A-Za-z0-9._-]+/g, '-')
157
+ .replace(/^[-.]+/, '')
158
+ .slice(0, exports.REPO_NAME_MAX)
159
+ .replace(/[-.]+$/, '');
160
+ return cleaned.length === 0 ? null : cleaned;
161
+ }
162
+ /**
163
+ * The default name for a repository: the last path segment of its normalised
164
+ * URL, sanitised. `https://github.com/acme/api` is `api`.
165
+ */
166
+ function repoNameFromUrl(url) {
167
+ const normalised = normaliseRepoUrl(url);
168
+ if (normalised === null)
169
+ return null;
170
+ const last = new URL(normalised).pathname.split('/').filter(Boolean).pop();
171
+ if (last === undefined)
172
+ return null;
173
+ let decoded = last;
174
+ try {
175
+ decoded = decodeURIComponent(last);
176
+ }
177
+ catch {
178
+ // A malformed escape stays as written; sanitising turns it into dashes.
179
+ }
180
+ return sanitiseRepoName(decoded);
181
+ }
182
+ //# sourceMappingURL=repo-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo-url.js","sourceRoot":"","sources":["../src/repo-url.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;;;AAwCH,4CAsDC;AAWD,4CASC;AAMD,0CAYC;AAlID,0FAA0F;AAC7E,QAAA,YAAY,GAAG,GAAG,CAAC;AAEhC,6DAA6D;AAChD,QAAA,aAAa,GAAG,GAAG,CAAC;AAEjC;;;;;;;;GAQG;AACH,MAAM,QAAQ,GAAG,8CAA8C,CAAC;AAEhE;;;;;;;;GAQG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,WAAW,EA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OAAO,CAAC,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "@looply/core",
3
- "version": "0.2.0",
4
- "description": "Shared event schema, state machines and ledger projection for looply",
5
- "license": "MIT",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "//exports": "The barrel re-exports ids.ts, whose `crypto` import no React Native bundler can resolve. `./ledger` is the platform-neutral projection (it imports only ./events, which imports nothing) offered as its own entry so a mobile app can have `reconcile` without Node. `main`/`types` are kept for the node10 resolvers this workspace still uses.",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "default": "./dist/index.js"
13
- },
14
- "./ledger": {
15
- "types": "./dist/ledger.d.ts",
16
- "default": "./dist/ledger.js"
17
- },
18
- "./activation-code": {
19
- "types": "./dist/activation-code.d.ts",
20
- "default": "./dist/activation-code.js"
21
- },
22
- "./package.json": "./package.json"
23
- },
24
- "files": [
25
- "dist",
26
- "README.md",
27
- "LICENSE"
28
- ],
29
- "scripts": {
30
- "build": "tsc -b",
31
- "clean": "tsc -b --clean",
32
- "prepack": "npm run build",
33
- "prepublishOnly": "npm run build"
34
- },
35
- "repository": {
36
- "type": "git",
37
- "url": "git+https://github.com/georgeemichel/looply.git"
38
- },
39
- "homepage": "https://looply-agent-app.web.app",
40
- "bugs": {
41
- "url": "https://github.com/georgeemichel/looply/issues"
42
- },
43
- "engines": {
44
- "node": ">=20"
45
- },
46
- "publishConfig": {
47
- "access": "public"
48
- }
49
- }
1
+ {
2
+ "name": "@looply/core",
3
+ "version": "0.4.0",
4
+ "description": "Shared event schema, state machines and ledger projection for looply",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "//exports": "The barrel re-exports ids.ts, whose `crypto` import no React Native bundler can resolve. `./ledger` is the platform-neutral projection (it imports only ./events, which imports nothing) offered as its own entry so a mobile app can have `reconcile` without Node. `main`/`types` are kept for the node10 resolvers this workspace still uses.",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./ledger": {
15
+ "types": "./dist/ledger.d.ts",
16
+ "default": "./dist/ledger.js"
17
+ },
18
+ "./activation-code": {
19
+ "types": "./dist/activation-code.d.ts",
20
+ "default": "./dist/activation-code.js"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc -b",
31
+ "clean": "tsc -b --clean",
32
+ "prepack": "npm run build",
33
+ "prepublishOnly": "npm run build"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/georgeemichel/looply.git"
38
+ },
39
+ "homepage": "https://looply-agent-app.web.app",
40
+ "bugs": {
41
+ "url": "https://github.com/georgeemichel/looply/issues"
42
+ },
43
+ "engines": {
44
+ "node": ">=20"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }