@trdrs/quickcharts 1.0.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +18 -0
  4. package/README.md +2325 -0
  5. package/THIRD-PARTY-NOTICES.md +263 -0
  6. package/dist/adapters/rest.d.ts +143 -0
  7. package/dist/adapters/rest.js +214 -0
  8. package/dist/adapters/rest.js.map +1 -0
  9. package/dist/ar-G7MVXRE4.js +1028 -0
  10. package/dist/ar-G7MVXRE4.js.map +1 -0
  11. package/dist/assets-C1GQvm0w.d.ts +1452 -0
  12. package/dist/ca_ES-EUSRU4VG.js +1028 -0
  13. package/dist/ca_ES-EUSRU4VG.js.map +1 -0
  14. package/dist/chunk-AKXIFHQN.js +172 -0
  15. package/dist/chunk-AKXIFHQN.js.map +1 -0
  16. package/dist/chunk-KFBQSPNA.js +107 -0
  17. package/dist/chunk-KFBQSPNA.js.map +1 -0
  18. package/dist/chunk-PD3DEWMQ.js +6959 -0
  19. package/dist/chunk-PD3DEWMQ.js.map +1 -0
  20. package/dist/de-2SVTG25S.js +1028 -0
  21. package/dist/de-2SVTG25S.js.map +1 -0
  22. package/dist/drawings.d.ts +237 -0
  23. package/dist/drawings.js +199 -0
  24. package/dist/drawings.js.map +1 -0
  25. package/dist/es-UDHZM4W7.js +1028 -0
  26. package/dist/es-UDHZM4W7.js.map +1 -0
  27. package/dist/feature-manifest.json +3453 -0
  28. package/dist/fr-35VN4G4S.js +1028 -0
  29. package/dist/fr-35VN4G4S.js.map +1 -0
  30. package/dist/he_IL-JPZMCURP.js +1028 -0
  31. package/dist/he_IL-JPZMCURP.js.map +1 -0
  32. package/dist/id_ID-XSTFHHJQ.js +1028 -0
  33. package/dist/id_ID-XSTFHHJQ.js.map +1 -0
  34. package/dist/index.d.ts +5487 -0
  35. package/dist/index.js +24040 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/it-EIY6JESQ.js +1028 -0
  38. package/dist/it-EIY6JESQ.js.map +1 -0
  39. package/dist/ja-42N4XRCW.js +1028 -0
  40. package/dist/ja-42N4XRCW.js.map +1 -0
  41. package/dist/ko-3VRPTIP3.js +1028 -0
  42. package/dist/ko-3VRPTIP3.js.map +1 -0
  43. package/dist/ms_MY-SKN7O6M5.js +1028 -0
  44. package/dist/ms_MY-SKN7O6M5.js.map +1 -0
  45. package/dist/pl-TYARHCLT.js +1028 -0
  46. package/dist/pl-TYARHCLT.js.map +1 -0
  47. package/dist/pt-72IIFLL4.js +1028 -0
  48. package/dist/pt-72IIFLL4.js.map +1 -0
  49. package/dist/quickcharts.css +6217 -0
  50. package/dist/resources-Ch8eA1Mw.d.ts +228 -0
  51. package/dist/rest-openapi.json +1664 -0
  52. package/dist/ru-TPH4F7IB.js +1028 -0
  53. package/dist/ru-TPH4F7IB.js.map +1 -0
  54. package/dist/sv-DC5RS67Z.js +1028 -0
  55. package/dist/sv-DC5RS67Z.js.map +1 -0
  56. package/dist/th-I6H6AOZ3.js +1028 -0
  57. package/dist/th-I6H6AOZ3.js.map +1 -0
  58. package/dist/theme-manifest.json +1246 -0
  59. package/dist/tr-7FSUVCNW.js +1028 -0
  60. package/dist/tr-7FSUVCNW.js.map +1 -0
  61. package/dist/vi-DLRPHLLH.js +1028 -0
  62. package/dist/vi-DLRPHLLH.js.map +1 -0
  63. package/dist/zh-ZXIQBBEP.js +1028 -0
  64. package/dist/zh-ZXIQBBEP.js.map +1 -0
  65. package/dist/zh_TW-TYNUJU7U.js +1028 -0
  66. package/dist/zh_TW-TYNUJU7U.js.map +1 -0
  67. package/package.json +100 -0
@@ -0,0 +1,263 @@
1
+ # Third-party notices for @trdrs/quickcharts
2
+
3
+ This document lists every third-party package in the dependency closure of `@trdrs/quickcharts`, with the license and copyright statement each package publishes. It is generated from the installed packages by `scripts/build-third-party-notices.mjs` on every build.
4
+
5
+ `@trdrs/quickcharts` bundles no third-party code. It declares one peer dependency that your application installs and bundles, and that peer installs one package of its own. Because your application bundle redistributes these packages, their license conditions attach to your product; this document tells you what each one asks for.
6
+
7
+ | Package | Version | License | Reached through |
8
+ |---|---|---|---|
9
+ | `fancy-canvas` | 2.1.0 | MIT | `lightweight-charts@5.2.0` |
10
+ | `lightweight-charts` | 5.2.0 | Apache-2.0 | peer dependency |
11
+
12
+ ## fancy-canvas 2.1.0
13
+
14
+ - License: MIT
15
+ - Repository: https://github.com/tradingview/fancy-canvas
16
+ - Copyright: Copyright (c) 2019 TradingView, Inc
17
+
18
+ The license text, as the repository states it at https://github.com/tradingview/fancy-canvas/blob/master/LICENSE:
19
+
20
+ ```
21
+ Copyright (c) 2019 TradingView, Inc
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ of this software and associated documentation files (the "Software"), to deal
25
+ in the Software without restriction, including without limitation the rights
26
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ copies of the Software, and to permit persons to whom the Software is
28
+ furnished to do so, subject to the following conditions:
29
+
30
+ The above copyright notice and this permission notice shall be included in all
31
+ copies or substantial portions of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
+ SOFTWARE.
40
+ ```
41
+
42
+ ## lightweight-charts 5.2.0
43
+
44
+ - License: Apache-2.0
45
+ - Repository: https://github.com/tradingview/lightweight-charts
46
+ - Copyright: Copyright 2023 TradingView, Inc.
47
+
48
+ The package README states an attribution requirement beside the license: present the text of its NOTICE file and a link to https://www.tradingview.com/ on a page of your website or application that your users can reach. The package's `attributionLogo` chart option is one documented way to satisfy the link.
49
+
50
+ The NOTICE file of lightweight-charts 5.2.0, reproduced verbatim from https://github.com/tradingview/lightweight-charts/blob/master/NOTICE:
51
+
52
+ ```
53
+ TradingView Lightweight Charts™
54
+ Copyright (с) 2025 TradingView, Inc. https://www.tradingview.com/
55
+ ```
56
+
57
+ The license text, from the package's own LICENSE file:
58
+
59
+ ```
60
+ Apache License
61
+ Version 2.0, January 2004
62
+ http://www.apache.org/licenses/
63
+
64
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
65
+
66
+ 1. Definitions.
67
+
68
+ "License" shall mean the terms and conditions for use, reproduction,
69
+ and distribution as defined by Sections 1 through 9 of this document.
70
+
71
+ "Licensor" shall mean the copyright owner or entity authorized by
72
+ the copyright owner that is granting the License.
73
+
74
+ "Legal Entity" shall mean the union of the acting entity and all
75
+ other entities that control, are controlled by, or are under common
76
+ control with that entity. For the purposes of this definition,
77
+ "control" means (i) the power, direct or indirect, to cause the
78
+ direction or management of such entity, whether by contract or
79
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
80
+ outstanding shares, or (iii) beneficial ownership of such entity.
81
+
82
+ "You" (or "Your") shall mean an individual or Legal Entity
83
+ exercising permissions granted by this License.
84
+
85
+ "Source" form shall mean the preferred form for making modifications,
86
+ including but not limited to software source code, documentation
87
+ source, and configuration files.
88
+
89
+ "Object" form shall mean any form resulting from mechanical
90
+ transformation or translation of a Source form, including but
91
+ not limited to compiled object code, generated documentation,
92
+ and conversions to other media types.
93
+
94
+ "Work" shall mean the work of authorship, whether in Source or
95
+ Object form, made available under the License, as indicated by a
96
+ copyright notice that is included in or attached to the work
97
+ (an example is provided in the Appendix below).
98
+
99
+ "Derivative Works" shall mean any work, whether in Source or Object
100
+ form, that is based on (or derived from) the Work and for which the
101
+ editorial revisions, annotations, elaborations, or other modifications
102
+ represent, as a whole, an original work of authorship. For the purposes
103
+ of this License, Derivative Works shall not include works that remain
104
+ separable from, or merely link (or bind by name) to the interfaces of,
105
+ the Work and Derivative Works thereof.
106
+
107
+ "Contribution" shall mean any work of authorship, including
108
+ the original version of the Work and any modifications or additions
109
+ to that Work or Derivative Works thereof, that is intentionally
110
+ submitted to Licensor for inclusion in the Work by the copyright owner
111
+ or by an individual or Legal Entity authorized to submit on behalf of
112
+ the copyright owner. For the purposes of this definition, "submitted"
113
+ means any form of electronic, verbal, or written communication sent
114
+ to the Licensor or its representatives, including but not limited to
115
+ communication on electronic mailing lists, source code control systems,
116
+ and issue tracking systems that are managed by, or on behalf of, the
117
+ Licensor for the purpose of discussing and improving the Work, but
118
+ excluding communication that is conspicuously marked or otherwise
119
+ designated in writing by the copyright owner as "Not a Contribution."
120
+
121
+ "Contributor" shall mean Licensor and any individual or Legal Entity
122
+ on behalf of whom a Contribution has been received by Licensor and
123
+ subsequently incorporated within the Work.
124
+
125
+ 2. Grant of Copyright License. Subject to the terms and conditions of
126
+ this License, each Contributor hereby grants to You a perpetual,
127
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
128
+ copyright license to reproduce, prepare Derivative Works of,
129
+ publicly display, publicly perform, sublicense, and distribute the
130
+ Work and such Derivative Works in Source or Object form.
131
+
132
+ 3. Grant of Patent License. Subject to the terms and conditions of
133
+ this License, each Contributor hereby grants to You a perpetual,
134
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
135
+ (except as stated in this section) patent license to make, have made,
136
+ use, offer to sell, sell, import, and otherwise transfer the Work,
137
+ where such license applies only to those patent claims licensable
138
+ by such Contributor that are necessarily infringed by their
139
+ Contribution(s) alone or by combination of their Contribution(s)
140
+ with the Work to which such Contribution(s) was submitted. If You
141
+ institute patent litigation against any entity (including a
142
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
143
+ or a Contribution incorporated within the Work constitutes direct
144
+ or contributory patent infringement, then any patent licenses
145
+ granted to You under this License for that Work shall terminate
146
+ as of the date such litigation is filed.
147
+
148
+ 4. Redistribution. You may reproduce and distribute copies of the
149
+ Work or Derivative Works thereof in any medium, with or without
150
+ modifications, and in Source or Object form, provided that You
151
+ meet the following conditions:
152
+
153
+ (a) You must give any other recipients of the Work or
154
+ Derivative Works a copy of this License; and
155
+
156
+ (b) You must cause any modified files to carry prominent notices
157
+ stating that You changed the files; and
158
+
159
+ (c) You must retain, in the Source form of any Derivative Works
160
+ that You distribute, all copyright, patent, trademark, and
161
+ attribution notices from the Source form of the Work,
162
+ excluding those notices that do not pertain to any part of
163
+ the Derivative Works; and
164
+
165
+ (d) If the Work includes a "NOTICE" text file as part of its
166
+ distribution, then any Derivative Works that You distribute must
167
+ include a readable copy of the attribution notices contained
168
+ within such NOTICE file, excluding those notices that do not
169
+ pertain to any part of the Derivative Works, in at least one
170
+ of the following places: within a NOTICE text file distributed
171
+ as part of the Derivative Works; within the Source form or
172
+ documentation, if provided along with the Derivative Works; or,
173
+ within a display generated by the Derivative Works, if and
174
+ wherever such third-party notices normally appear. The contents
175
+ of the NOTICE file are for informational purposes only and
176
+ do not modify the License. You may add Your own attribution
177
+ notices within Derivative Works that You distribute, alongside
178
+ or as an addendum to the NOTICE text from the Work, provided
179
+ that such additional attribution notices cannot be construed
180
+ as modifying the License.
181
+
182
+ You may add Your own copyright statement to Your modifications and
183
+ may provide additional or different license terms and conditions
184
+ for use, reproduction, or distribution of Your modifications, or
185
+ for any such Derivative Works as a whole, provided Your use,
186
+ reproduction, and distribution of the Work otherwise complies with
187
+ the conditions stated in this License.
188
+
189
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
190
+ any Contribution intentionally submitted for inclusion in the Work
191
+ by You to the Licensor shall be under the terms and conditions of
192
+ this License, without any additional terms or conditions.
193
+ Notwithstanding the above, nothing herein shall supersede or modify
194
+ the terms of any separate license agreement you may have executed
195
+ with Licensor regarding such Contributions.
196
+
197
+ 6. Trademarks. This License does not grant permission to use the trade
198
+ names, trademarks, service marks, or product names of the Licensor,
199
+ except as required for reasonable and customary use in describing the
200
+ origin of the Work and reproducing the content of the NOTICE file.
201
+
202
+ 7. Disclaimer of Warranty. Unless required by applicable law or
203
+ agreed to in writing, Licensor provides the Work (and each
204
+ Contributor provides its Contributions) on an "AS IS" BASIS,
205
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
206
+ implied, including, without limitation, any warranties or conditions
207
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
208
+ PARTICULAR PURPOSE. You are solely responsible for determining the
209
+ appropriateness of using or redistributing the Work and assume any
210
+ risks associated with Your exercise of permissions under this License.
211
+
212
+ 8. Limitation of Liability. In no event and under no legal theory,
213
+ whether in tort (including negligence), contract, or otherwise,
214
+ unless required by applicable law (such as deliberate and grossly
215
+ negligent acts) or agreed to in writing, shall any Contributor be
216
+ liable to You for damages, including any direct, indirect, special,
217
+ incidental, or consequential damages of any character arising as a
218
+ result of this License or out of the use or inability to use the
219
+ Work (including but not limited to damages for loss of goodwill,
220
+ work stoppage, computer failure or malfunction, or any and all
221
+ other commercial damages or losses), even if such Contributor
222
+ has been advised of the possibility of such damages.
223
+
224
+ 9. Accepting Warranty or Additional Liability. While redistributing
225
+ the Work or Derivative Works thereof, You may choose to offer,
226
+ and charge a fee for, acceptance of support, warranty, indemnity,
227
+ or other liability obligations and/or rights consistent with this
228
+ License. However, in accepting such obligations, You may act only
229
+ on Your own behalf and on Your sole responsibility, not on behalf
230
+ of any other Contributor, and only if You agree to indemnify,
231
+ defend, and hold each Contributor harmless for any liability
232
+ incurred by, or claims asserted against, such Contributor by reason
233
+ of your accepting any such warranty or additional liability.
234
+
235
+ END OF TERMS AND CONDITIONS
236
+
237
+ APPENDIX: How to apply the Apache License to your work.
238
+
239
+ To apply the Apache License to your work, attach the following
240
+ boilerplate notice, with the fields enclosed by brackets "[]"
241
+ replaced with your own identifying information. (Don't include
242
+ the brackets!) The text should be enclosed in the appropriate
243
+ comment syntax for the file format. We also recommend that a
244
+ file or class name and description of purpose be included on the
245
+ same "printed page" as the copyright notice for easier
246
+ identification within third-party archives.
247
+
248
+ Copyright 2023 TradingView, Inc.
249
+
250
+ Licensed under the Apache License, Version 2.0 (the "License");
251
+ you may not use this file except in compliance with the License.
252
+ You may obtain a copy of the License at
253
+
254
+ http://www.apache.org/licenses/LICENSE-2.0
255
+
256
+ Unless required by applicable law or agreed to in writing, software
257
+ distributed under the License is distributed on an "AS IS" BASIS,
258
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
259
+ See the License for the specific language governing permissions and
260
+ limitations under the License.
261
+ ```
262
+
263
+ trdrs is not affiliated with, sponsored by, or endorsed by TradingView, Inc.
@@ -0,0 +1,143 @@
1
+ import { C as ChartSaveLoadAdapter } from '../resources-Ch8eA1Mw.js';
2
+
3
+ /** The three template collections. */
4
+ type RestTemplateKind = 'study' | 'drawing' | 'palette';
5
+ /** Which collection a request addresses. Templates are three collections rather than one, so the
6
+ * kind is part of the address rather than a field inside it. */
7
+ type RestCollection = {
8
+ family: 'charts' | 'layouts' | 'drawings';
9
+ } | {
10
+ family: 'templates';
11
+ kind: RestTemplateKind;
12
+ };
13
+ /** A row's identity plus the exact version a reader saw. */
14
+ interface RestResourceRef {
15
+ id: string;
16
+ /** Opaque: compared for equality, never parsed or ordered. */
17
+ revision: string;
18
+ }
19
+ /** A listing: metadata only, so a picker paints without fetching content. `items` is the same key
20
+ * in every family, so one reader serves all four. */
21
+ interface RestListResponse<Meta> {
22
+ items: Meta[];
23
+ }
24
+ /** A read: the ref the document stands at, and the document. */
25
+ interface RestLoadResponse<Body> extends RestResourceRef {
26
+ body: Body;
27
+ }
28
+ /** A create, update or delete that landed: the ref the service now holds (for a delete, the one it
29
+ * removed), and the listing row the write produced where the service computes one. */
30
+ interface RestWriteResponse<Meta> extends RestResourceRef {
31
+ meta?: Meta;
32
+ }
33
+ /** The 409 body: the ref that stands now, so the caller reloads it and re-decides. */
34
+ interface RestConflictBody {
35
+ error: 'conflict';
36
+ current: RestResourceRef;
37
+ }
38
+ /** The 404 body. */
39
+ interface RestNotFoundBody {
40
+ error: 'not_found';
41
+ }
42
+ /** The 428 body. */
43
+ interface RestRevisionRequiredBody {
44
+ error: 'revision_required';
45
+ }
46
+ /** A saved chart's listing row. `updatedAt` is ms since epoch, stamped by the service. */
47
+ interface RestChartMeta extends RestResourceRef {
48
+ name: string;
49
+ symbol: string;
50
+ timeframe: string;
51
+ updatedAt: number;
52
+ }
53
+ /** A saved chart. `content` is the chart's serialized state, opaque to the service. */
54
+ interface RestChartBody {
55
+ name: string;
56
+ symbol: string;
57
+ timeframe: string;
58
+ content: string;
59
+ }
60
+ /** A saved multi-chart layout's listing row. `symbol` and `timeframe` are the active chart's when the
61
+ * layout was last saved; a service that does not keep them leaves them out. */
62
+ interface RestLayoutMeta extends RestResourceRef {
63
+ name: string;
64
+ symbol?: string;
65
+ timeframe?: string;
66
+ updatedAt: number;
67
+ }
68
+ interface RestLayoutBody {
69
+ name: string;
70
+ symbol?: string;
71
+ timeframe?: string;
72
+ content: string;
73
+ }
74
+ /** A drawings document's listing row. One context holds at most one document, so the collection
75
+ * answers zero rows or one. */
76
+ interface RestDrawingsMeta extends RestResourceRef {
77
+ updatedAt: number;
78
+ }
79
+ /** A drawings document, as the service stores it: the document's own JSON, as opaque text. */
80
+ interface RestDrawingsBody {
81
+ content: string;
82
+ }
83
+ /** A template's listing row. `tool` scopes a drawing template to its tool; study and palette
84
+ * templates carry none. */
85
+ interface RestTemplateMeta extends RestResourceRef {
86
+ name: string;
87
+ tool?: string;
88
+ updatedAt: number;
89
+ }
90
+ interface RestTemplateBody {
91
+ name: string;
92
+ tool?: string;
93
+ content: string;
94
+ }
95
+
96
+ /** What the adapter asks a request function to do. Deliberately the subset of `RequestInit` the
97
+ * contract needs, so a host implementing this by hand implements four fields rather than thirty,
98
+ * and a plain `fetch` accepts it unchanged. */
99
+ interface RestRequestInit {
100
+ method: string;
101
+ headers: Record<string, string>;
102
+ /** The JSON payload, on a create and an update; absent on a read and a delete. */
103
+ body?: string;
104
+ signal?: AbortSignal;
105
+ }
106
+ /** What the adapter reads back. The subset of a `Response` the contract needs, so a host may return
107
+ * a real `Response` or its own object of the same shape. */
108
+ interface RestResponse {
109
+ readonly status: number;
110
+ text(): Promise<string>;
111
+ }
112
+ /** The host's transport. `fetch` satisfies it; so does a wrapper that adds the host's authorization,
113
+ * its base headers, its retries or its telemetry. The adapter calls it and reads what it answers,
114
+ * and does nothing else with the network. */
115
+ type RestRequest = (url: string, init: RestRequestInit) => Promise<RestResponse>;
116
+ interface RestSaveLoadOptions {
117
+ /** Where the host mounts the wire contract's routes. Every path is appended to it, so an origin,
118
+ * a path prefix, or a bare path are all fine. There is no default: the chart does not know where
119
+ * a host's service lives, and guessing would be a request nobody asked for. */
120
+ baseUrl: string;
121
+ /** How a request is made. Required, for the same reason. */
122
+ request: RestRequest;
123
+ }
124
+ /** A request the service answered in a way the contract does not define: a status with no meaning
125
+ * here (`http`), or a body that is not the shape the route promises (`invalid-payload`). It carries
126
+ * what the caller needs to decide: which request, and what came back. */
127
+ declare class RestSaveLoadError extends Error {
128
+ readonly name = "RestSaveLoadError";
129
+ readonly reason: 'http' | 'invalid-payload';
130
+ readonly status: number;
131
+ readonly method: string;
132
+ readonly url: string;
133
+ constructor(init: {
134
+ reason: 'http' | 'invalid-payload';
135
+ status: number;
136
+ method: string;
137
+ url: string;
138
+ detail: string;
139
+ });
140
+ }
141
+ declare function createRestSaveLoadAdapter(options: RestSaveLoadOptions): ChartSaveLoadAdapter;
142
+
143
+ export { type RestChartBody, type RestChartMeta, type RestCollection, type RestConflictBody, type RestDrawingsBody, type RestDrawingsMeta, type RestLayoutBody, type RestLayoutMeta, type RestListResponse, type RestLoadResponse, type RestNotFoundBody, type RestRequest, type RestRequestInit, type RestResourceRef, type RestResponse, type RestRevisionRequiredBody, RestSaveLoadError, type RestSaveLoadOptions, type RestTemplateBody, type RestTemplateKind, type RestTemplateMeta, type RestWriteResponse, createRestSaveLoadAdapter };
@@ -0,0 +1,214 @@
1
+ import {
2
+ ResourceAbortError
3
+ } from "../chunk-KFBQSPNA.js";
4
+ import {
5
+ DRAWING_DOCUMENT_VERSION,
6
+ drawingContextKey,
7
+ parseDrawingDocument
8
+ } from "../chunk-AKXIFHQN.js";
9
+
10
+ // src/adapters/rest/wire.ts
11
+ var REST_IF_MATCH_HEADER = "if-match";
12
+ var REST_STATUS = {
13
+ /** The id is unknown, deleted, or another principal's. */
14
+ notFound: 404,
15
+ /** The quoted revision is not the one that stands; the body carries the one that is. */
16
+ conflict: 409,
17
+ /** A conditional route was reached with no `If-Match`. The adapter always sends one. */
18
+ revisionRequired: 428
19
+ };
20
+ function restCollectionPath(collection) {
21
+ return collection.family === "templates" ? `/templates/${encodeURIComponent(collection.kind)}` : `/${collection.family}`;
22
+ }
23
+ function restItemPath(collection, id) {
24
+ return `${restCollectionPath(collection)}/${encodeURIComponent(id)}`;
25
+ }
26
+ function restDrawingContextToken(context) {
27
+ const parts = [String(context.version), context.kind];
28
+ if (context.kind === "chart-local") parts.push(context.layoutId, context.chartId);
29
+ else if (context.kind === "layout-shared") parts.push(context.layoutId);
30
+ return parts.map((part) => encodeURIComponent(part).replace(/\./g, "%2E")).join(".");
31
+ }
32
+ function restDrawingsQuery(context) {
33
+ return `symbol=${encodeURIComponent(context.symbol)}&context=${encodeURIComponent(restDrawingContextToken(context))}`;
34
+ }
35
+
36
+ // src/adapters/rest/index.ts
37
+ var RestSaveLoadError = class extends Error {
38
+ name = "RestSaveLoadError";
39
+ reason;
40
+ status;
41
+ method;
42
+ url;
43
+ constructor(init) {
44
+ super(`${init.method} ${init.url}: ${init.detail}`);
45
+ this.reason = init.reason;
46
+ this.status = init.status;
47
+ this.method = init.method;
48
+ this.url = init.url;
49
+ }
50
+ };
51
+ var isRecord = (value) => typeof value === "object" && value !== null;
52
+ var refOf = (value) => {
53
+ if (!isRecord(value)) return null;
54
+ const { id, revision } = value;
55
+ return typeof id === "string" && id !== "" && typeof revision === "string" ? { id, revision } : null;
56
+ };
57
+ var listingFacts = (from) => ({
58
+ ...typeof from.symbol === "string" ? { symbol: from.symbol } : {},
59
+ ...typeof from.timeframe === "string" ? { timeframe: from.timeframe } : {}
60
+ });
61
+ var trimBase = (baseUrl) => baseUrl.replace(/\/+$/, "");
62
+ function createRestSaveLoadAdapter(options) {
63
+ const base = trimBase(options.baseUrl);
64
+ const request = options.request;
65
+ async function call(deps) {
66
+ if (deps.signal?.aborted) throw new ResourceAbortError();
67
+ const url = `${base}${deps.path}`;
68
+ const headers = {};
69
+ if (deps.body !== void 0) headers["content-type"] = "application/json";
70
+ if (deps.ref) headers[REST_IF_MATCH_HEADER] = deps.ref.revision;
71
+ const init = { method: deps.method, headers };
72
+ if (deps.body !== void 0) init.body = JSON.stringify(deps.body);
73
+ if (deps.signal) init.signal = deps.signal;
74
+ const response = await request(url, init);
75
+ const text = await response.text();
76
+ return { status: response.status, text };
77
+ }
78
+ function payload(method, url, answer) {
79
+ let parsed = null;
80
+ try {
81
+ parsed = answer.text === "" ? null : JSON.parse(answer.text);
82
+ } catch {
83
+ parsed = null;
84
+ }
85
+ if (!isRecord(parsed))
86
+ throw new RestSaveLoadError({ reason: "invalid-payload", status: answer.status, method, url, detail: "the response is not a JSON object" });
87
+ return parsed;
88
+ }
89
+ const httpError = (method, url, status) => new RestSaveLoadError({ reason: "http", status, method, url, detail: `unexpected status ${status}` });
90
+ function store(deps) {
91
+ const collectionPath = deps.query ? `${restCollectionPath(deps.collection)}?${deps.query}` : restCollectionPath(deps.collection);
92
+ const itemPath = (id) => restItemPath(deps.collection, id);
93
+ const written = (method, path, answer, carriesMeta) => {
94
+ const url = `${base}${path}`;
95
+ if (answer.status === REST_STATUS.notFound) return { kind: "not-found" };
96
+ if (answer.status === REST_STATUS.conflict) {
97
+ const conflict = payload(method, url, answer);
98
+ const current = refOf(conflict.current);
99
+ if (!current) throw new RestSaveLoadError({ reason: "invalid-payload", status: answer.status, method, url, detail: "the conflict states no current ref" });
100
+ return { kind: "conflict", current };
101
+ }
102
+ if (answer.status < 200 || answer.status >= 300) throw httpError(method, url, answer.status);
103
+ const body = payload(method, url, answer);
104
+ const ref = refOf(body);
105
+ if (!ref) throw new RestSaveLoadError({ reason: "invalid-payload", status: answer.status, method, url, detail: "the write states no ref" });
106
+ const outcome = { kind: "ok", ref };
107
+ if (carriesMeta && body.meta !== void 0) outcome.value = deps.metaOf(body.meta);
108
+ return outcome;
109
+ };
110
+ return {
111
+ async list(signal) {
112
+ const answer = await call({ method: "GET", path: collectionPath, signal });
113
+ const url = `${base}${collectionPath}`;
114
+ if (answer.status < 200 || answer.status >= 300) throw httpError("GET", url, answer.status);
115
+ const body = payload("GET", url, answer);
116
+ if (!Array.isArray(body.items)) throw new RestSaveLoadError({ reason: "invalid-payload", status: answer.status, method: "GET", url, detail: "the listing states no items array" });
117
+ return body.items.map(deps.metaOf);
118
+ },
119
+ async load(id, signal) {
120
+ const path = itemPath(id);
121
+ const url = `${base}${path}`;
122
+ const answer = await call({ method: "GET", path, signal });
123
+ if (answer.status === REST_STATUS.notFound) return null;
124
+ if (answer.status < 200 || answer.status >= 300) throw httpError("GET", url, answer.status);
125
+ const body = payload("GET", url, answer);
126
+ const ref = refOf(body);
127
+ if (!ref || body.body === void 0 || !isRecord(body.body))
128
+ throw new RestSaveLoadError({ reason: "invalid-payload", status: answer.status, method: "GET", url, detail: "the read states no ref and body" });
129
+ return { ref, body: deps.bodyOf(body.body, answer, url) };
130
+ },
131
+ async create(body, signal) {
132
+ const answer = await call({ method: "POST", path: collectionPath, body: deps.wireOf(body), signal });
133
+ return written("POST", collectionPath, answer, true);
134
+ },
135
+ async update(ref, body, signal) {
136
+ const path = itemPath(ref.id);
137
+ const answer = await call({ method: "PUT", path, body: deps.wireOf(body), ref, signal });
138
+ return written("PUT", path, answer, true);
139
+ },
140
+ async remove(ref, signal) {
141
+ const path = itemPath(ref.id);
142
+ const answer = await call({ method: "DELETE", path, ref, signal });
143
+ return written("DELETE", path, answer, false);
144
+ }
145
+ };
146
+ }
147
+ const drawingStores = /* @__PURE__ */ new Map();
148
+ const templateStores = /* @__PURE__ */ new Map();
149
+ return {
150
+ charts: store({
151
+ collection: { family: "charts" },
152
+ metaOf: (r) => ({ id: r.id, revision: r.revision, name: r.name, symbol: r.symbol, timeframe: r.timeframe, updatedAt: r.updatedAt }),
153
+ bodyOf: (w) => ({ name: w.name, symbol: w.symbol, timeframe: w.timeframe, content: w.content }),
154
+ wireOf: (b) => ({ name: b.name, symbol: b.symbol, timeframe: b.timeframe, content: b.content })
155
+ }),
156
+ layouts: store({
157
+ collection: { family: "layouts" },
158
+ metaOf: (r) => ({ id: r.id, revision: r.revision, name: r.name, ...listingFacts(r), updatedAt: r.updatedAt }),
159
+ bodyOf: (w) => ({ name: w.name, ...listingFacts(w), content: w.content }),
160
+ wireOf: (b) => ({ name: b.name, ...listingFacts(b), content: b.content })
161
+ }),
162
+ drawings(context) {
163
+ const key = drawingContextKey(context);
164
+ let held = drawingStores.get(key);
165
+ if (!held) {
166
+ held = store({
167
+ collection: { family: "drawings" },
168
+ query: restDrawingsQuery(context),
169
+ metaOf: (r) => ({ id: r.id, revision: r.revision, updatedAt: r.updatedAt }),
170
+ // The document is the one body the chart itself reads, so this is where a stored row is
171
+ // proved to be a document FOR THIS CONTEXT before the chart sees one. A row that is not
172
+ // is refused rather than read as an empty document: an empty read is followed by a save,
173
+ // and that save would replace the row it misread.
174
+ bodyOf: (w, answer, url) => documentOf(w.content, context, answer.status, url),
175
+ wireOf: (b) => ({ content: JSON.stringify(b) })
176
+ });
177
+ drawingStores.set(key, held);
178
+ }
179
+ return held;
180
+ },
181
+ templates(kind) {
182
+ let held = templateStores.get(kind);
183
+ if (!held) {
184
+ held = store({
185
+ collection: { family: "templates", kind },
186
+ metaOf: (r) => ({ id: r.id, revision: r.revision, name: r.name, ...r.tool === void 0 ? {} : { tool: r.tool }, updatedAt: r.updatedAt }),
187
+ bodyOf: (w) => ({ name: w.name, ...w.tool === void 0 ? {} : { tool: w.tool }, content: w.content }),
188
+ wireOf: (b) => ({ name: b.name, ...b.tool === void 0 ? {} : { tool: b.tool }, content: b.content })
189
+ });
190
+ templateStores.set(kind, held);
191
+ }
192
+ return held;
193
+ }
194
+ };
195
+ }
196
+ function documentOf(content, context, status, url) {
197
+ const refuse = (detail) => new RestSaveLoadError({ reason: "invalid-payload", status, method: "GET", url, detail });
198
+ let raw = null;
199
+ try {
200
+ raw = JSON.parse(content);
201
+ } catch {
202
+ throw refuse("the stored drawings row is not JSON");
203
+ }
204
+ if (!isRecord(raw)) throw refuse("the stored drawings row is not a drawings document");
205
+ if (raw.version !== DRAWING_DOCUMENT_VERSION) throw refuse(`the stored drawings row is not a version-${String(DRAWING_DOCUMENT_VERSION)} document`);
206
+ if (isRecord(raw.context) && drawingContextKey(raw.context) !== drawingContextKey(context))
207
+ throw refuse("the stored drawings row is another context's document");
208
+ return parseDrawingDocument(raw, context);
209
+ }
210
+ export {
211
+ RestSaveLoadError,
212
+ createRestSaveLoadAdapter
213
+ };
214
+ //# sourceMappingURL=rest.js.map