@supabase/phoenix 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.
Files changed (49) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +122 -0
  3. package/assets/js/phoenix/ajax.js +116 -0
  4. package/assets/js/phoenix/channel.js +331 -0
  5. package/assets/js/phoenix/constants.js +35 -0
  6. package/assets/js/phoenix/index.js +212 -0
  7. package/assets/js/phoenix/longpoll.js +192 -0
  8. package/assets/js/phoenix/presence.js +208 -0
  9. package/assets/js/phoenix/push.js +134 -0
  10. package/assets/js/phoenix/serializer.js +133 -0
  11. package/assets/js/phoenix/socket.js +747 -0
  12. package/assets/js/phoenix/timer.js +48 -0
  13. package/assets/js/phoenix/types.js +184 -0
  14. package/assets/js/phoenix/utils.js +16 -0
  15. package/package.json +58 -0
  16. package/priv/static/favicon.ico +0 -0
  17. package/priv/static/phoenix-orange.png +0 -0
  18. package/priv/static/phoenix.cjs.js +1812 -0
  19. package/priv/static/phoenix.cjs.js.map +7 -0
  20. package/priv/static/phoenix.js +1834 -0
  21. package/priv/static/phoenix.min.js +2 -0
  22. package/priv/static/phoenix.mjs +1789 -0
  23. package/priv/static/phoenix.mjs.map +7 -0
  24. package/priv/static/phoenix.png +0 -0
  25. package/priv/static/types/ajax.d.ts +10 -0
  26. package/priv/static/types/ajax.d.ts.map +1 -0
  27. package/priv/static/types/channel.d.ts +167 -0
  28. package/priv/static/types/channel.d.ts.map +1 -0
  29. package/priv/static/types/constants.d.ts +36 -0
  30. package/priv/static/types/constants.d.ts.map +1 -0
  31. package/priv/static/types/index.d.ts +10 -0
  32. package/priv/static/types/index.d.ts.map +1 -0
  33. package/priv/static/types/longpoll.d.ts +29 -0
  34. package/priv/static/types/longpoll.d.ts.map +1 -0
  35. package/priv/static/types/presence.d.ts +107 -0
  36. package/priv/static/types/presence.d.ts.map +1 -0
  37. package/priv/static/types/push.d.ts +70 -0
  38. package/priv/static/types/push.d.ts.map +1 -0
  39. package/priv/static/types/serializer.d.ts +74 -0
  40. package/priv/static/types/serializer.d.ts.map +1 -0
  41. package/priv/static/types/socket.d.ts +284 -0
  42. package/priv/static/types/socket.d.ts.map +1 -0
  43. package/priv/static/types/timer.d.ts +36 -0
  44. package/priv/static/types/timer.d.ts.map +1 -0
  45. package/priv/static/types/types.d.ts +280 -0
  46. package/priv/static/types/types.d.ts.map +1 -0
  47. package/priv/static/types/utils.d.ts +2 -0
  48. package/priv/static/types/utils.d.ts.map +1 -0
  49. package/tsconfig.json +20 -0
@@ -0,0 +1,280 @@
1
+ /**
2
+ * MISC
3
+ */
4
+ export type Params = Record<string, unknown>;
5
+ export type Closure<T> = T | (() => T);
6
+ /**
7
+ * CHANNEL
8
+ */
9
+ export type ChannelBindingCallback = (payload: unknown, ref: string | null | undefined, joinRef: string) => void;
10
+ /**
11
+ * CHANNEL
12
+ */
13
+ export type ChannelOnErrorCallback = (reason: unknown) => void;
14
+ /**
15
+ * CHANNEL
16
+ */
17
+ export type ChannelBinding = ({
18
+ event: string;
19
+ ref: number;
20
+ callback: ChannelBindingCallback;
21
+ });
22
+ /**
23
+ * CHANNEL
24
+ */
25
+ export type ChannelOnMessage = (event: string, payload?: unknown, ref?: string | null, joinRef?: string | null) => unknown;
26
+ /**
27
+ * CHANNEL
28
+ */
29
+ export type ChannelFilterBindings = (binding: ChannelBinding, payload: unknown, ref?: string | null) => boolean;
30
+ /**
31
+ * CONSTANTS
32
+ */
33
+ export type Vsn = "1.0.0" | "2.0.0";
34
+ /**
35
+ * CONSTANTS
36
+ */
37
+ export type SocketState = (typeof SOCKET_STATES)[keyof typeof SOCKET_STATES];
38
+ /**
39
+ * CONSTANTS
40
+ */
41
+ export type ChannelState = (typeof CHANNEL_STATES)[keyof typeof CHANNEL_STATES];
42
+ /**
43
+ * CONSTANTS
44
+ */
45
+ export type ChannelEvent = (typeof CHANNEL_EVENTS)[keyof typeof CHANNEL_EVENTS];
46
+ /**
47
+ * CONSTANTS
48
+ */
49
+ export type Transport = (typeof TRANSPORTS)[keyof typeof TRANSPORTS];
50
+ /**
51
+ * CONSTANTS
52
+ */
53
+ export type XhrState = (typeof XHR_STATES)[keyof typeof XHR_STATES];
54
+ /**
55
+ * PRESENCE
56
+ */
57
+ export type PresenceEvents = {
58
+ state: string;
59
+ diff: string;
60
+ };
61
+ /**
62
+ * PRESENCE
63
+ */
64
+ export type PresenceOnJoin = (key: string, currentPresence: PresenceState, newPresence: PresenceState) => void;
65
+ /**
66
+ * PRESENCE
67
+ */
68
+ export type PresenceOnLeave = (key: string, currentPresence: PresenceState, leftPresence: PresenceState) => void;
69
+ /**
70
+ * PRESENCE
71
+ */
72
+ export type PresenceOnSync = () => void;
73
+ /**
74
+ * PRESENCE
75
+ */
76
+ export type PresenceDiff = ({
77
+ joins: PresenceState;
78
+ leaves: PresenceState;
79
+ });
80
+ /**
81
+ * PRESENCE
82
+ */
83
+ export type PresenceState = ({
84
+ metas: {
85
+ phx_ref?: string;
86
+ phx_ref_prev?: string;
87
+ [key: string]: any;
88
+ }[];
89
+ });
90
+ /**
91
+ * PRESENCE
92
+ */
93
+ export type PresenceOptions = {
94
+ events?: PresenceEvents | undefined;
95
+ };
96
+ /**
97
+ * SERIALIZER
98
+ */
99
+ export type Message<T> = ({
100
+ join_ref?: string | null;
101
+ ref?: string | null;
102
+ event: string;
103
+ topic: string;
104
+ payload: T;
105
+ });
106
+ export type Encode<T> = (msg: Message<Record<string, any>>, callback: (result: ArrayBuffer | string) => T) => T;
107
+ export type Decode<T> = (rawPayload: ArrayBuffer | string, callback: (msg: Message<unknown>) => T) => T;
108
+ /**
109
+ * SOCKET
110
+ */
111
+ export type SocketTransport = (typeof WebSocket | typeof LongPoll);
112
+ /**
113
+ * SOCKET
114
+ */
115
+ export type SocketOnOpen = () => void;
116
+ /**
117
+ * SOCKET
118
+ */
119
+ export type SocketOnClose = (event: CloseEvent) => void;
120
+ /**
121
+ * SOCKET
122
+ */
123
+ export type SocketOnError = (error: Event, transportBefore: SocketTransport, establishedBefore: number) => void;
124
+ /**
125
+ * SOCKET
126
+ */
127
+ export type SocketOnMessage = (rawMessage: Message<unknown>) => void;
128
+ /**
129
+ * SOCKET
130
+ */
131
+ export type SocketStateChangeCallbacks = ({
132
+ open: [string, SocketOnOpen][];
133
+ close: [string, SocketOnClose][];
134
+ error: [string, SocketOnError][];
135
+ message: [string, SocketOnMessage][];
136
+ });
137
+ /**
138
+ * SOCKET
139
+ */
140
+ export type HeartbeatStatus = "sent" | "ok" | "error" | "timeout" | "disconnected";
141
+ /**
142
+ * SOCKET
143
+ */
144
+ export type HeartbeatCallback = (status: HeartbeatStatus, latency?: number) => void;
145
+ /**
146
+ * SOCKET
147
+ */
148
+ export type SocketOptions = {
149
+ /**
150
+ * - The Websocket Transport, for example WebSocket or Phoenix.LongPoll.
151
+ */
152
+ transport?: SocketTransport | undefined;
153
+ /**
154
+ * - The millisecond time to attempt the primary transport
155
+ * before falling back to the LongPoll transport. Disabled by default.
156
+ */
157
+ longPollFallbackMs?: number | undefined;
158
+ /**
159
+ * - The millisecond time before LongPoll transport times out. Default 20000.
160
+ */
161
+ longpollerTimeout?: number | undefined;
162
+ /**
163
+ * - When true, enables debug logging. Default false.
164
+ */
165
+ debug?: boolean | undefined;
166
+ /**
167
+ * - The function to encode outgoing messages.
168
+ * Defaults to JSON encoder.
169
+ */
170
+ encode?: Encode<void> | undefined;
171
+ /**
172
+ * - The function to decode incoming messages.
173
+ * Defaults to JSON:
174
+ *
175
+ * ```javascript
176
+ * (payload, callback) => callback(JSON.parse(payload))
177
+ * ```
178
+ */
179
+ decode?: Decode<void> | undefined;
180
+ /**
181
+ * - The default timeout in milliseconds to trigger push timeouts.
182
+ * Defaults `DEFAULT_TIMEOUT`
183
+ */
184
+ timeout?: number | undefined;
185
+ /**
186
+ * - The millisec interval to send a heartbeat message
187
+ */
188
+ heartbeatIntervalMs?: number | undefined;
189
+ /**
190
+ * - Whether to automatically send heartbeats after
191
+ * connection is established.
192
+ *
193
+ * Defaults to true.
194
+ */
195
+ autoSendHeartbeat?: boolean | undefined;
196
+ /**
197
+ * - The optional function to handle heartbeat status and latency.
198
+ */
199
+ heartbeatCallback?: HeartbeatCallback | undefined;
200
+ /**
201
+ * - The optional function that returns the
202
+ * socket reconnect interval, in milliseconds.
203
+ *
204
+ * Defaults to stepped backoff of:
205
+ *
206
+ * ```javascript
207
+ * function(tries){
208
+ * return [10, 50, 100, 150, 200, 250, 500, 1000, 2000][tries - 1] || 5000
209
+ * }
210
+ * ````
211
+ */
212
+ reconnectAfterMs?: ((tries: number) => number) | undefined;
213
+ /**
214
+ * - The optional function that returns the millisec
215
+ * rejoin interval for individual channels.
216
+ *
217
+ * ```javascript
218
+ * function(tries){
219
+ * return [1000, 2000, 5000][tries - 1] || 10000
220
+ * }
221
+ * ````
222
+ */
223
+ rejoinAfterMs?: ((tries: number) => number) | undefined;
224
+ /**
225
+ * - The optional function for specialized logging, ie:
226
+ *
227
+ * ```javascript
228
+ * function(kind, msg, data) {
229
+ * console.log(`${kind}: ${msg}`, data)
230
+ * }
231
+ * ```
232
+ */
233
+ logger?: ((kind: string, msg: string, data: any) => void) | undefined;
234
+ /**
235
+ * - The optional params to pass when connecting
236
+ */
237
+ params?: Closure<Params> | undefined;
238
+ /**
239
+ * - the optional authentication token to be exposed on the server
240
+ * under the `:auth_token` connect_info key.
241
+ */
242
+ authToken?: string | undefined;
243
+ /**
244
+ * - The binary type to use for binary WebSocket frames.
245
+ *
246
+ * Defaults to "arraybuffer"
247
+ */
248
+ binaryType?: BinaryType | undefined;
249
+ /**
250
+ * - The serializer's protocol version to send on connect.
251
+ *
252
+ * Defaults to DEFAULT_VSN.
253
+ */
254
+ vsn?: Vsn | undefined;
255
+ /**
256
+ * - An optional Storage compatible object
257
+ * Phoenix uses sessionStorage for longpoll fallback history. Overriding the store is
258
+ * useful when Phoenix won't have access to `sessionStorage`. For example, This could
259
+ * happen if a site loads a cross-domain channel in an iframe. Example usage:
260
+ *
261
+ * class InMemoryStorage {
262
+ * constructor() { this.storage = {} }
263
+ * getItem(keyName) { return this.storage[keyName] || null }
264
+ * removeItem(keyName) { delete this.storage[keyName] }
265
+ * setItem(keyName, keyValue) { this.storage[keyName] = keyValue }
266
+ * }
267
+ */
268
+ sessionStorage?: Storage | undefined;
269
+ /**
270
+ * - Callback ran before socket tries to reconnect.
271
+ */
272
+ beforeReconnect?: (() => Promise<void>) | undefined;
273
+ };
274
+ import type { SOCKET_STATES } from "./constants";
275
+ import type { CHANNEL_STATES } from "./constants";
276
+ import type { CHANNEL_EVENTS } from "./constants";
277
+ import type { TRANSPORTS } from "./constants";
278
+ import type { XHR_STATES } from "./constants";
279
+ import type LongPoll from "./longpoll";
280
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../assets/js/phoenix/types.js"],"names":[],"mappings":";;;qBAMa,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;oBAIvB,CAAC,IACD,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;;;;qCAMb,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI;;;;qCAC3E,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI;;;;6BACzB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,sBAAsB,CAAA;CAAC,CAAC;;;;+BAChE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,EAAG,MAAM,OAAA,EAAE,OAAO,CAAC,EAAG,MAAM,OAAA,KAAK,OAAO;;;;oCAC/E,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,EAAG,MAAM,OAAA,KAAK,OAAO;;;;kBAOrE,OAAO,G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>(value: T | (() => T)): () => T;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../assets/js/phoenix/utils.js"],"names":[],"mappings":"AAQO,wBAJK,CAAC,SACH,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GACX,MAAM,CAAC,CASlB"}
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "include": [
3
+ "assets/js/phoenix/**/*.js"
4
+ ],
5
+ "compilerOptions": {
6
+ "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
7
+ "module": "ESNext", /* Specify what module code is generated. */
8
+ "moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
9
+ "rootDir": "./assets/js/phoenix", /* Specify the root folder within your source files. */
10
+ "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
11
+ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
12
+ "declarationMap": true, /* Create sourcemaps for d.ts files. */
13
+ "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
14
+ "outDir": "./priv/static/types", /* Specify an output folder for all emitted files. */
15
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
16
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
17
+ "strict": true, /* Enable all strict type-checking options. */
18
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
19
+ }
20
+ }