Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fireproof/netlify

Package Overview
Dependencies
Maintainers
0
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fireproof/netlify - npm Package Compare versions

Comparing version 0.19.10-dev-marty6 to 0.19.10

index.global.js

512

index.js

@@ -0,3 +1,365 @@

var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// node_modules/.pnpm/@jspm+core@2.0.1/node_modules/@jspm/core/nodelibs/browser/process.js
var process_exports = {};
__export(process_exports, {
_debugEnd: () => _debugEnd,
_debugProcess: () => _debugProcess,
_events: () => _events,
_eventsCount: () => _eventsCount,
_exiting: () => _exiting,
_fatalExceptions: () => _fatalExceptions,
_getActiveHandles: () => _getActiveHandles,
_getActiveRequests: () => _getActiveRequests,
_kill: () => _kill,
_linkedBinding: () => _linkedBinding,
_maxListeners: () => _maxListeners,
_preload_modules: () => _preload_modules,
_rawDebug: () => _rawDebug,
_startProfilerIdleNotifier: () => _startProfilerIdleNotifier,
_stopProfilerIdleNotifier: () => _stopProfilerIdleNotifier,
_tickCallback: () => _tickCallback,
abort: () => abort,
addListener: () => addListener,
allowedNodeEnvironmentFlags: () => allowedNodeEnvironmentFlags,
arch: () => arch,
argv: () => argv,
argv0: () => argv0,
assert: () => assert,
binding: () => binding,
chdir: () => chdir,
config: () => config,
cpuUsage: () => cpuUsage,
cwd: () => cwd,
debugPort: () => debugPort,
default: () => process,
dlopen: () => dlopen,
domain: () => domain,
emit: () => emit,
emitWarning: () => emitWarning,
env: () => env,
execArgv: () => execArgv,
execPath: () => execPath,
exit: () => exit,
features: () => features,
hasUncaughtExceptionCaptureCallback: () => hasUncaughtExceptionCaptureCallback,
hrtime: () => hrtime,
kill: () => kill,
listeners: () => listeners,
memoryUsage: () => memoryUsage,
moduleLoadList: () => moduleLoadList,
nextTick: () => nextTick,
off: () => off,
on: () => on,
once: () => once,
openStdin: () => openStdin,
pid: () => pid,
platform: () => platform,
ppid: () => ppid,
prependListener: () => prependListener,
prependOnceListener: () => prependOnceListener,
reallyExit: () => reallyExit,
release: () => release,
removeAllListeners: () => removeAllListeners,
removeListener: () => removeListener,
resourceUsage: () => resourceUsage,
setSourceMapsEnabled: () => setSourceMapsEnabled,
setUncaughtExceptionCaptureCallback: () => setUncaughtExceptionCaptureCallback,
stderr: () => stderr,
stdin: () => stdin,
stdout: () => stdout,
title: () => title,
umask: () => umask,
uptime: () => uptime,
version: () => version,
versions: () => versions
});
function unimplemented(name) {
throw new Error("Node.js process " + name + " is not supported by JSPM core outside of Node.js");
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue)
return;
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length)
drainQueue();
}
function drainQueue() {
if (draining)
return;
var timeout = setTimeout(cleanUpNextTick, 0);
draining = true;
var len = queue.length;
while (len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue)
currentQueue[queueIndex].run();
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
clearTimeout(timeout);
}
function nextTick(fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++)
args[i - 1] = arguments[i];
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining)
setTimeout(drainQueue, 0);
}
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function() {
this.fun.apply(null, this.array);
};
var title = "browser";
var arch = "x64";
var platform = "browser";
var env = {
PATH: "/usr/bin",
LANG: navigator.language + ".UTF-8",
PWD: "/",
HOME: "/home",
TMP: "/tmp"
};
var argv = ["/usr/bin/node"];
var execArgv = [];
var version = "v16.8.0";
var versions = {};
var emitWarning = function(message, type) {
console.warn((type ? type + ": " : "") + message);
};
var binding = function(name) {
unimplemented("binding");
};
var umask = function(mask) {
return 0;
};
var cwd = function() {
return "/";
};
var chdir = function(dir) {
};
var release = {
name: "node",
sourceUrl: "",
headersUrl: "",
libUrl: ""
};
function noop() {
}
var _rawDebug = noop;
var moduleLoadList = [];
function _linkedBinding(name) {
unimplemented("_linkedBinding");
}
var domain = {};
var _exiting = false;
var config = {};
function dlopen(name) {
unimplemented("dlopen");
}
function _getActiveRequests() {
return [];
}
function _getActiveHandles() {
return [];
}
var reallyExit = noop;
var _kill = noop;
var cpuUsage = function() {
return {};
};
var resourceUsage = cpuUsage;
var memoryUsage = cpuUsage;
var kill = noop;
var exit = noop;
var openStdin = noop;
var allowedNodeEnvironmentFlags = {};
function assert(condition, message) {
if (!condition) throw new Error(message || "assertion error");
}
var features = {
inspector: false,
debug: false,
uv: false,
ipv6: false,
tls_alpn: false,
tls_sni: false,
tls_ocsp: false,
tls: false,
cached_builtins: true
};
var _fatalExceptions = noop;
var setUncaughtExceptionCaptureCallback = noop;
function hasUncaughtExceptionCaptureCallback() {
return false;
}
var _tickCallback = noop;
var _debugProcess = noop;
var _debugEnd = noop;
var _startProfilerIdleNotifier = noop;
var _stopProfilerIdleNotifier = noop;
var stdout = void 0;
var stderr = void 0;
var stdin = void 0;
var abort = noop;
var pid = 2;
var ppid = 1;
var execPath = "/bin/usr/node";
var debugPort = 9229;
var argv0 = "node";
var _preload_modules = [];
var setSourceMapsEnabled = noop;
var _performance = {
now: typeof performance !== "undefined" ? performance.now.bind(performance) : void 0,
timing: typeof performance !== "undefined" ? performance.timing : void 0
};
if (_performance.now === void 0) {
nowOffset = Date.now();
if (_performance.timing && _performance.timing.navigationStart) {
nowOffset = _performance.timing.navigationStart;
}
_performance.now = () => Date.now() - nowOffset;
}
var nowOffset;
function uptime() {
return _performance.now() / 1e3;
}
var nanoPerSec = 1e9;
function hrtime(previousTimestamp) {
var baseNow = Math.floor((Date.now() - _performance.now()) * 1e-3);
var clocktime = _performance.now() * 1e-3;
var seconds = Math.floor(clocktime) + baseNow;
var nanoseconds = Math.floor(clocktime % 1 * 1e9);
if (previousTimestamp) {
seconds = seconds - previousTimestamp[0];
nanoseconds = nanoseconds - previousTimestamp[1];
if (nanoseconds < 0) {
seconds--;
nanoseconds += nanoPerSec;
}
}
return [seconds, nanoseconds];
}
hrtime.bigint = function(time) {
var diff = hrtime(time);
if (typeof BigInt === "undefined") {
return diff[0] * nanoPerSec + diff[1];
}
return BigInt(diff[0] * nanoPerSec) + BigInt(diff[1]);
};
var _maxListeners = 10;
var _events = {};
var _eventsCount = 0;
function on() {
return process;
}
var addListener = on;
var once = on;
var off = on;
var removeListener = on;
var removeAllListeners = on;
var emit = noop;
var prependListener = on;
var prependOnceListener = on;
function listeners(name) {
return [];
}
var process = {
version,
versions,
arch,
platform,
release,
_rawDebug,
moduleLoadList,
binding,
_linkedBinding,
_events,
_eventsCount,
_maxListeners,
on,
addListener,
once,
off,
removeListener,
removeAllListeners,
emit,
prependListener,
prependOnceListener,
listeners,
domain,
_exiting,
config,
dlopen,
uptime,
_getActiveRequests,
_getActiveHandles,
reallyExit,
_kill,
cpuUsage,
resourceUsage,
memoryUsage,
kill,
exit,
openStdin,
allowedNodeEnvironmentFlags,
assert,
features,
_fatalExceptions,
setUncaughtExceptionCaptureCallback,
hasUncaughtExceptionCaptureCallback,
emitWarning,
nextTick,
_tickCallback,
_debugProcess,
_debugEnd,
_startProfilerIdleNotifier,
_stopProfilerIdleNotifier,
stdout,
stdin,
stderr,
abort,
umask,
chdir,
cwd,
env,
title,
argv,
execArgv,
pid,
ppid,
execPath,
debugPort,
hrtime,
argv0,
_preload_modules,
setSourceMapsEnabled
};
// src/connection-from-store.ts
import { runtimeFn, URI } from "@adviser/cement";
import { BuildURI, runtimeFn, URI } from "@adviser/cement";
import { bs, ensureLogger } from "@fireproof/core";

@@ -22,9 +384,9 @@ var ConnectionFromStore = class extends bs.ConnectionBase {

};
const name = this.url.getParam("name");
if (!name) {
throw this.logger.Error().Msg("name parameter is missing in the URL").AsError();
const rName = this.url.getParamResult("name");
if (rName.isErr()) {
throw this.logger.Error().Err(rName).Msg("missing Parameter").AsError();
}
const storeRuntime = bs.toStoreRuntime({ stores }, this.sthis);
const loader = {
name,
name: rName.Ok(),
ebOpts: {

@@ -54,15 +416,14 @@ logger: this.logger,

} else {
base = "file://./dist/kb-dir-partykit?fs=mem";
base = "file://./dist/kb-dir-partykit";
}
}
const kbUrl = new URL(base);
kbUrl.searchParams.set("extractKey", "_deprecated_internal_api");
const kbUrl = BuildURI.from(base);
kbUrl.defParam("extractKey", "_deprecated_internal_api");
sthis.env.set("FP_KEYBAG_URL", kbUrl.toString());
sthis.logger.Debug().Str("keyBagUrl", kbUrl.toString()).Str("base", base).Msg("Make keybag url extractable");
sthis.logger.Debug().Url(kbUrl, "keyBagUrl").Msg("Make keybag url extractable");
}
// src/netlify/gateway.ts
import { KeyedResolvOnce, Result, URI as URI2, BuildURI } from "@adviser/cement";
import { KeyedResolvOnce, Result, URI as URI2, BuildURI as BuildURI2, exception2Result } from "@adviser/cement";
import { bs as bs2, getStore, NotFoundError, ensureSuperLog } from "@fireproof/core";
import fetch from "cross-fetch";
var NetlifyGateway = class {

@@ -81,6 +442,7 @@ constructor(sthis) {

}
let name = url.getParam("name");
if (!name) {
return Result.Err(new Error("Name not found in the URI"));
const rName = url.getParamResult("name");
if (rName.isErr()) {
return Result.Err(rName.Err());
}
let name = rName.Ok();
const index = url.getParam("index");

@@ -95,7 +457,6 @@ if (index) {

}
const fetchUrl = new URL(remoteBaseUrl);
fetchUrl.searchParams.set("meta", name);
const response = await fetch(fetchUrl.toString(), { method: "DELETE" });
const fetchUrl = BuildURI2.from(remoteBaseUrl).setParam("meta", name).URI();
const response = await fetch(fetchUrl.asURL(), { method: "DELETE" });
if (!response.ok) {
return Result.Err(new Error(`Failed to destroy meta database: ${response.statusText}`));
return this.logger.Error().Str("status", response.statusText).Msg("Failed to destroy meta database").ResultError();
}

@@ -109,3 +470,3 @@ return Result.Ok(void 0);

const urlString = `${protocol}://${host}${path}`;
const baseUrl = BuildURI.from(urlString).URI();
const baseUrl = BuildURI2.from(urlString).URI();
const ret = uri.build().defParam("version", "v0.1-netlify").defParam("remoteBaseUrl", baseUrl.toString()).URI();

@@ -119,10 +480,8 @@ return Result.Ok(ret);

const { store } = getStore(url, this.sthis, (...args) => args.join("/"));
const key = url.getParam("key");
if (!key) {
return Result.Err(new Error("Key not found in the URI"));
const rParams = url.getParamsResult("key", "name");
if (rParams.isErr()) {
return this.logger.Error().Url(url).Err(rParams).Msg("Put Error").ResultError();
}
let name = url.getParam("name");
if (!name) {
return Result.Err(new Error("Name not found in the URI"));
}
const { key } = rParams.Ok();
let { name } = rParams.Ok();
const index = url.getParam("index");

@@ -137,9 +496,9 @@ if (index) {

}
const fetchUrl = new URL(remoteBaseUrl);
const fetchUrl = BuildURI2.from(remoteBaseUrl);
switch (store) {
case "meta":
fetchUrl.searchParams.set("meta", name);
fetchUrl.setParam("meta", name);
break;
default:
fetchUrl.searchParams.set("car", key);
fetchUrl.setParam("car", key);
break;

@@ -154,5 +513,5 @@ }

}
const done = await fetch(fetchUrl.toString(), { method: "PUT", body });
const done = await fetch(fetchUrl.URI().asURL(), { method: "PUT", body });
if (!done.ok) {
return Result.Err(new Error(`failed to upload ${store} ${done.statusText}`));
return this.logger.Error().Url(fetchUrl.URI()).Int("status", done.status).Msg(`failed to upload ${store}`).ResultError();
}

@@ -163,10 +522,8 @@ return Result.Ok(void 0);

const { store } = getStore(url, this.sthis, (...args) => args.join("/"));
const key = url.getParam("key");
if (!key) {
return Result.Err(new Error("Key not found in the URI"));
const rParams = url.getParamsResult("key", "name", "remoteBaseUrl");
if (rParams.isErr()) {
return Result.Err(rParams.Err());
}
let name = url.getParam("name");
if (!name) {
return Result.Err(new Error("Name not found in the URI"));
}
const { key, remoteBaseUrl } = rParams.Ok();
let { name } = rParams.Ok();
const index = url.getParam("index");

@@ -177,16 +534,18 @@ if (index) {

name += ".fp";
const remoteBaseUrl = url.getParam("remoteBaseUrl");
if (!remoteBaseUrl) {
return Result.Err(new Error("Remote base URL not found in the URI"));
}
const fetchUrl = new URL(remoteBaseUrl);
const fetchUrl = BuildURI2.from(remoteBaseUrl);
switch (store) {
case "meta":
fetchUrl.searchParams.set("meta", name);
fetchUrl.setParam("meta", name);
break;
default:
fetchUrl.searchParams.set("car", key);
fetchUrl.setParam("car", key);
break;
}
const response = await fetch(fetchUrl.toString());
const rresponse = await exception2Result(() => {
return fetch(fetchUrl.URI().asURL());
});
if (rresponse.isErr()) {
return this.logger.Error().Url(fetchUrl).Err(rresponse).Msg("Failed to fetch").ResultError();
}
const response = rresponse.Ok();
if (!response.ok) {

@@ -206,7 +565,8 @@ return Result.Err(new NotFoundError(`${store} not found: ${url}`));

const { store } = getStore(url, this.sthis, (...args) => args.join("/"));
const key = url.getParam("key");
let name = url.getParam("name");
if (!name) {
return Result.Err(new Error("Name not found in the URI"));
const rParams = url.getParamsResult("key", "name", "remoteBaseUrl");
if (rParams.isErr()) {
return Result.Err(rParams.Err());
}
const { key, remoteBaseUrl } = rParams.Ok();
let { name } = rParams.Ok();
const index = url.getParam("index");

@@ -217,10 +577,6 @@ if (index) {

name += ".fp";
const remoteBaseUrl = url.getParam("remoteBaseUrl");
if (!remoteBaseUrl) {
return Result.Err(new Error("Remote base URL not found in the URI"));
}
const fetchUrl = new URL(remoteBaseUrl);
const fetchUrl = BuildURI2.from(remoteBaseUrl);
switch (store) {
case "meta":
fetchUrl.searchParams.set("meta", name);
fetchUrl.setParam("meta", name);
break;

@@ -231,6 +587,6 @@ default:

}
fetchUrl.searchParams.set("car", key);
fetchUrl.setParam("car", key);
break;
}
const response = await fetch(fetchUrl.toString(), { method: "DELETE" });
const response = await fetch(fetchUrl.URI().asURL(), { method: "DELETE" });
if (!response.ok) {

@@ -241,7 +597,8 @@ return Result.Err(new Error(`Failed to delete car: ${response.statusText}`));

}
// this should be a shared fallback
async subscribe(url, callback) {
url = url.build().setParam("key", "main").URI();
url = url.build().setParam("key", "main").defParam("interval", "100").defParam("maxInterval", "3000").URI();
let lastData = void 0;
let interval = 100;
const initInterval = parseInt(url.getParam("interval") || "100", 10);
const maxInterval = parseInt(url.getParam("maxInterval") || "3000", 10);
let interval = initInterval;
const fetchData = async () => {

@@ -254,5 +611,5 @@ const result = await this.get(url);

callback(data);
interval = 100;
interval = initInterval;
} else {
interval *= 2;
interval = Math.min(interval * 2, maxInterval);
}

@@ -299,11 +656,11 @@ }

// src/netlify/index.ts
import { KeyedResolvOnce as KeyedResolvOnce2 } from "@adviser/cement";
if (typeof process !== "undefined" && process.env && !process.env.FP_KEYBAG_URL?.includes("extractKey=_deprecated_internal_api")) {
const url = new URL(process.env.FP_KEYBAG_URL || "file://./dist/kb-dir-netlify?fs=mem");
url.searchParams.set("extractKey", "_deprecated_internal_api");
process.env.FP_KEYBAG_URL = url.toString();
import { BuildURI as BuildURI3, KeyedResolvOnce as KeyedResolvOnce2, runtimeFn as runtimeFn2 } from "@adviser/cement";
if (!runtimeFn2().isBrowser) {
const url = BuildURI3.from(process_exports.env.FP_KEYBAG_URL || "file://./dist/kb-dir-netlify");
url.setParam("extractKey", "_deprecated_internal_api");
process_exports.env.FP_KEYBAG_URL = url.toString();
}
registerNetlifyStoreProtocol();
var connectionCache = new KeyedResolvOnce2();
var connect = (db, remoteDbName = "", url = "http://localhost:8888?protocol=ws") => {
var connect = (db, remoteDbName = "", url = "netlify://localhost:8888?protocol=ws") => {
const { sthis, blockstore, name: dbName } = db;

@@ -313,13 +670,10 @@ if (!dbName) {

}
const urlObj = new URL(url);
const existingName = urlObj.searchParams.get("name");
urlObj.searchParams.set("name", remoteDbName || existingName || dbName);
urlObj.searchParams.set("localName", dbName);
urlObj.searchParams.set("storekey", `@${dbName}:data@`);
const fpUrl = urlObj.toString().replace("http://", "netlify://").replace("https://", "netlify://");
console.log("fpUrl", fpUrl);
return connectionCache.get(fpUrl).once(() => {
const urlObj = BuildURI3.from(url);
const existingName = urlObj.getParam("name");
urlObj.defParam("name", remoteDbName || existingName || dbName);
urlObj.defParam("localName", dbName);
urlObj.defParam("storekey", `@${dbName}:data@`);
return connectionCache.get(urlObj.toString()).once(() => {
makeKeyBagUrlExtractable(sthis);
console.log("Connecting to netlify", fpUrl);
const connection = connectionFactory(sthis, fpUrl);
const connection = connectionFactory(sthis, urlObj);
connection.connect_X(blockstore);

@@ -326,0 +680,0 @@ return connection;

11

package.json
{
"name": "@fireproof/netlify",
"version": "0.19.10-dev-marty6",
"version": "0.19.10",
"description": "PartyKit gateway for Netlify",
"main": "./index.cjs",
"module": "./index.js",
"browser": "./index.global.js",
"exports": {

@@ -11,2 +12,3 @@ ".": {

"require": "./index.cjs",
"script": "./index.global.js",
"types": "./index.d.ts"

@@ -22,3 +24,4 @@ }

"index.js.map",
"index.cjs.map"
"index.cjs.map",
"server.ts"
],

@@ -35,7 +38,7 @@ "type": "module",

"dependencies": {
"@netlify/blobs": "^7.4.0",
"@netlify/blobs": "^8.1.0",
"cross-fetch": "^4.0.0",
"@fireproof/core": "0.19.10-dev-marty6"
"@fireproof/core": "0.19.10"
},
"scripts": {}
}

@@ -1,9 +0,53 @@

# Testing
# `@fireproof/netlify`
All connectors are enabled by default in the Fireproof test suite. To run a test for a single connector, you can use the Vitest workspace configuration.
[Fireproof](https://use-fireproof.com) is an embedded JavaScript document database that runs in the browser (or anywhere with JavaScript) and **[connects to any cloud](https://www.npmjs.com/package/@fireproof/connect)**.
For example, to run tests for the PartyKit connector only, you can use the following command:
This module, `@fireproof/netlify`, allows you to connect your Fireproof database to Netlify, enabling you to sync your data across multiple users in real-time.
```console
$ npm test -- --project partykit
## Get started
We assume you already have an app that uses Fireproof in the browser, and you want to setup collaboration among multiple users via the cloud. To write your first Fireproof app, see the [Fireproof quickstart](https://use-fireproof.com/docs/react-tutorial), otherwise read on.
### 1. Install
In your existing Fireproof app install the connector:
```sh
npm install @fireproof/netlify
```
In your netlify project, install the `@netlify/blobs` package:
```sh
npm install @netlify/blobs
```
And finally, copy the `server.ts` file from this repo into your project:
```sh
cp node_modules/@fireproof/netlify/server.ts netlify/edge-functions/fireproof.ts
```
### 2. Connect
You're all done on the server, and ready to develop locally and then deploy with no further changes. Now you just need to connect to the Netlify in your client code:
```js
// you already have this in your app
import { useFireproof } from "use-fireproof";
// add this line
import { connect } from "@fireproof/netlify";
```
Now later in your app connect to the party (be sure to do this a component that runs on every render, like your root component or layout):
```js
const { database } = useFireproof('my-app-database-name')
const connection = connect(database, '', process.env.NEXT_PUBLIC_NETLIFY_HOST!)
```
The `connect` function is idempotent and designed to be safe to call on every render.
### 3. Collaborate
Now you can use Fireproof as you normally would, and it will sync in realtime with other users. Any existing apps you have that use the [live query](https://use-fireproof.com/docs/react-hooks/use-live-query) or [subscription](https://use-fireproof.com/docs/database-api/database#subscribe) APIs will automatically render multi-user updates.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc