open-index/open-npm huggingface dataset:
npm package: @kessler/firebase-events
Description: A simple library to send events to firestore database
Author: Yaniv Kessler
Latest version: 1.1.0

# firebase-events

A simple library to send events to firestore database

## general usage

```js

const { open } = require('@kessler/firebase-events')
const { onRequest } = require('firebase-functions/v2/https')
const logger = require('firebase-functions/logger')

exports.helloWorld = onRequest((req, res) => {
  const { newEvent, updateEvent } = await open('events')  
  const startEvent = newEvent('start', { functionName: 'helloWorld', type: 'start'})

  logger.info('Hello logs!', { structuredData: true })

  updateEvent(startEvent, { type: 'end' })
})

```

## timer

```js

const { open } = require('@kessler/firebase-events')
const { onRequest } = require('firebase-functions/v2/https')
const logger = require('firebase-functions/logger')

exports.helloWorld = onRequest((req, res) => {
  const { timer } = await open()
  const timerEvent = timer('function_duration', { fnName: 'helloWorld2' })
  logger.info('Hello logs!', { structuredData: true })
  await timerEvent.send()
})

```




1. enable firestore database in your firebase project
2. npm install @kessler/firebase-events
3. update your function code
4. deploy your function
npm package: @kessler/parse-arguments
Description: parse command line style positional and named arguments, eg. `cmd positional --name=foo`
Author: Yaniv Kessler
Latest version: 2.0.1
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# parse-arguments
A small lib for parsing command line arguments strings or arrays. E.g:

```"positional --flag --namedArgument=namedParam"```

# Install
```
npm i -S @kessler/parse-arguments
```

# Example
```js
const parseArguments = require('@kessler/parse-arguments')

const { positional, named, warnings } = parseArguments('positional --flag --named1 val1 --named2=val2')

// an array works too:
parseArguments(['positional', '--flag', '--namedArgument', 'namedParam'])
```
npm package: @kessler/repl
Description: a personal lib for building repls
Author: Yaniv Kessler
Latest version: 0.0.2
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# @kessler/repl (wip)

a personal lib for building repls

## Install
```
npm i @kessler/repl
```

## usage

index.js

```js
const REPL  = require('@kessler/repl')

const commands = [
    { 
        name: ['foo', 'f'],
        impl: ({ cli, session, params }) => cli.print('hi')
    }
]

REPL.start(commands)
```

## scripts
```
node index script.cli
```

script.cli
```
foo;
foo;
foo;
```
npm package: @kessler/s3-store
Description: a CRUD layer over s3 that utilizes conditional writes to maintain strong consistency for optimistic concurrency
Author: Yaniv Kessler
Latest version: 3.2.1

# @kessler/s3-store

a CRUD+extras layer over s3 that utilizes conditional reads and writes to maintain strong consistency for optimistic concurrency. Loosely based on this [article](https://www.architecture-weekly.com/p/using-s3-but-not-the-way-you-expected)

to create or access object, call `createObject` or `getObject`. Both will return an etag that you can use to `putObjectIfMatch` later. 

The etag is a strong consistency token that you can use to ensure that the object has not been modified since you last read it.

Please note that an `putObjectIfMatch` is a full overwrite of the object.
However, in most cases you should already have a copy of the object in memory, so you can just modify it and call `putObjectIfMatch` with the new object. The call will fail if the object has been modified since you last read it, which is the desired behavior. In that case all you need to do is to read the object again, modify it and call `putObjectIfMatch` again. This is of course a technical action, rather than a product one. In real world use cases you will maybe want to notify the user that the object has been modified and ask them to confirm the changes.

## installation

```bash
npm install @kessler/s3-store
```

## usage

### conveniece / simplified API for json objects

```javascript
import createS3Store, { createJsonWrapper } from '@kessler/s3-store'

const store = createJsonWrapper(createS3Store('my-bucket'))
const key = 'test-object'

const object = { hello: 'world' }
const createTag = await store.createObject(key, object)
const updateTag = await store.putObjectIfMatch(key, {...object, foo: 'bar '}, createTag)

// will only work if the object exists and was not modified
const getResult = await store.getObjectIfMatch(key, updateTag)
// getResult deeply equals { hello: 'world', foo: 'bar' }

// use this if you don't have any etag and want to get the object
// for the first time.
const [getResult1, getTag] = await store.getObject(key)
```

### lower level API any type of objects

```javascript
import createS3Store from '@kessler/s3-store'

const store = createS3Store('my-bucket', /* { client: optionally provide your own s3 client} */)
const key = 'test-object'
const body = JSON.stringify({ hello: 'world' })
const contentType = 'application/json'

// Create object
const createResult = await store.createObject(key, body, contentType)
//createResult.response === AWS sdk response

const updateResult = await store.putObjectIfMatch(key, updateBody, createResult.etag, contentType)
//updateResult.response === AWS sdk response

// Get object with etag
const getIfMatchResult = await store.getObjectIfMatch(key, updateResult.etag)
//getIfMatchResult.response === AWS sdk response
console.log(await getIfMatch.asString())

```
npm package: @kessler/serverless-onehook
Description: one hook to rule them all
Author: Yaniv Kessler
Latest version: 1.0.1
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# serverless one hook

- easily create plugins without publishing them 
- assign a hook before and after all existing hooks

`npm i -s @kessler/serverless-onehook`

```yaml
plugins:
    - "@kessler/serverless-onehook"
```
create a `oneHook.js` at the base of your project:
```js
module.exports = (onehook) => {
    // this module is run in during the construction of the plugin instance
    // so you can do anything that you would do in a normal sls plugin class
    onehook.commands = { ... }
    onehook.hooks = { ... }

    // but also, you can just skip the whole plugin class thing and just do hooks
    onehook.before('deploy:deploy', () => {})

    // will run before the "after" of deploy deploy
    onehook.before('after:deploy:deploy', () => { })

    // will run after the "after" of deploy deploy
    onehook.after('after:deploy:deploy', () => { })

    // an array containing all existing hook names
    // please note that what you get here probably (but i didn't check) depends
    // on the plugin load order, but in any case, all the core plugins (but not enterprise)
    // are loaded before this plugin
    console.log(onehook.existingHookNames)
}
```

### customize the location of oneHook.js

```yaml
plugins:
    - "@kessler/serverless-onehook"
custom:
    hookPath: something relative to project root (sls project roo)
```

### hooks reference
https://gist.github.com/HyperBrain/50d38027a8f57778d5b0f135d80ea406